Update documentation system: improve structure, search, and editor
This commit is contained in:
+8
-5
@@ -189,7 +189,7 @@
|
||||
<div class="docs-body">${WhatIDoMD.render(article.body)}</div>
|
||||
${(article.files && article.files.length) ? `<div class="docs-attachments">
|
||||
<div class="docs-attachments-title">Вложения</div>
|
||||
<ul class="docs-attachments-list">${article.files.map(f => `<li><a href="${esc(f.path)}" target="_blank" rel="noopener">${esc(f.name)}</a> <span class="docs-attach-size">${fmtBytes(f.size_bytes)}</span></li>`).join('')}</ul>
|
||||
<ul class="docs-attachments-list">${article.files.map(f => { const isImg = f._kind === 'image'; const captionInput = isImg ? `<div class="docs-caption-row"><input class="docs-caption-input" data-caption-for="${f.id}" value="${esc(f.caption || '')}" placeholder="Подпись (alt/title)" maxlength="300"><button type="button" class="btn-primary ghost" data-file-act="caption" title="Сохранить подпись">✓</button></div>` : ''; return `<li><a href="${esc(f.path)}" target="_blank" rel="noopener">${esc(f.name)}</a>${captionInput} <span class="docs-attach-size">${fmtBytes(f.size_bytes)}</span></li>`; }).join('')}</ul>
|
||||
</div>` : ''}
|
||||
</article>`;
|
||||
}
|
||||
@@ -583,7 +583,8 @@
|
||||
return /\.(jpe?g|png|gif|webp|bmp|avif|ico|jfif)$/i.test(String(f.name || f.path || ''));
|
||||
}
|
||||
function insertDocFileLink(f) {
|
||||
const md = isImageFile(f) ? `` : `[${f.name}](${f.path})`;
|
||||
const alt = (f.caption || f.name || 'картинка').replace(/\\./g, '\\.');
|
||||
const md = isImageFile(f) ? `` : `[${f.name}](${f.path})`;
|
||||
insertBlock(md);
|
||||
}
|
||||
|
||||
@@ -612,9 +613,10 @@
|
||||
return;
|
||||
}
|
||||
imgLibGrid.innerHTML = items.map(it => `
|
||||
<div class="docs-imglib-item" data-img-path="${esc(it.path)}" title="${esc(it.path)}">
|
||||
<div class="docs-imglib-item" data-img-path="${esc(it.path)}" data-img-caption="${esc(it.caption || '')}" title="${esc(it.path)}">
|
||||
<img src="${esc('/uploads/thumb/' + it.path.split('/').pop())}" alt="" loading="lazy">
|
||||
<div class="docs-imglib-name">${esc(it.path.split('/').pop())}</div>
|
||||
${it.caption ? '<div class="docs-imglib-caption">' + esc(it.caption) + '</div>' : ''}
|
||||
</div>`).join('');
|
||||
} catch (e) {
|
||||
imgLibGrid.innerHTML = '<div class="docs-empty">' + esc(e.message) + '</div>';
|
||||
@@ -887,8 +889,9 @@
|
||||
if (!item) return;
|
||||
const p = item.dataset.imgPath;
|
||||
if (!p) return;
|
||||
const name = p.split('/').pop().replace(/\.[^.]+$/, '');
|
||||
insertBlock(``);
|
||||
const caption = item.dataset.imgCaption || '';
|
||||
const alt = caption || p.split("/").pop().replace(/\.[^.]+$/, "");
|
||||
insertBlock(``);
|
||||
if (imgLibModal) imgLibModal.classList.remove('open');
|
||||
showToast('Картинка вставлена');
|
||||
});
|
||||
|
||||
+3
-4
@@ -27,12 +27,11 @@
|
||||
return `\u0000${codes.length - 1}\u0000`;
|
||||
});
|
||||
text = esc(text);
|
||||
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (m, alt, src, title) => {
|
||||
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (m, alt, src) => {
|
||||
const url = safeUrl(src.replace(/&/g, '&'));
|
||||
if (!url) return alt;
|
||||
const t = title ? title.replace(/&/g, '&') : '';
|
||||
const img = `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}"${t ? ` title="${esc(t)}"` : ''} loading="lazy">`;
|
||||
if (t) return `<figure class="md-figure">${img}<figcaption>${esc(t)}</figcaption></figure>`;
|
||||
const img = `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}" loading="lazy">`;
|
||||
if (alt) return `<figure class="md-figure">${img}<figcaption>${esc(alt)}</figcaption></figure>`;
|
||||
return img;
|
||||
});
|
||||
text = text.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, label, href) => {
|
||||
|
||||
Reference in New Issue
Block a user