Ohjeet: kuva-upload -toiminto Markdown-editoriin
- "Kuva" -nappi toolbarissa avaa tiedostovalitsimen - Kuva uploadataan serverille (max 5MB, PNG/JPG/GIF/WebP) - Markdown  -tagi lisätään automaattisesti editoriin - Kuva renderöityy lukunäkymässä ja esikatselussa - API: guide_image_upload (upload) + guide_image (serve) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
28
script.js
28
script.js
@@ -3500,6 +3500,8 @@ function renderMarkdown(md) {
|
||||
html = html.replace(/\*\*\*(.+?)\*\*\*/g, '<strong><em>$1</em></strong>');
|
||||
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
||||
html = html.replace(/\*(.+?)\*/g, '<em>$1</em>');
|
||||
// Kuvat (ennen linkkejä!)
|
||||
html = html.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1" style="max-width:100%;border-radius:8px;margin:0.5rem 0;">');
|
||||
// Linkit
|
||||
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
|
||||
// Lainaukset
|
||||
@@ -3731,6 +3733,32 @@ document.getElementById('btn-guide-preview-toggle')?.addEventListener('click', (
|
||||
}
|
||||
});
|
||||
|
||||
// Kuva-upload
|
||||
document.getElementById('btn-guide-image')?.addEventListener('click', () => {
|
||||
document.getElementById('guide-image-input')?.click();
|
||||
});
|
||||
document.getElementById('guide-image-input')?.addEventListener('change', async (e) => {
|
||||
const file = e.target.files[0];
|
||||
if (!file) return;
|
||||
const formData = new FormData();
|
||||
formData.append('image', file);
|
||||
try {
|
||||
const res = await fetch(`${API}?action=guide_image_upload`, {
|
||||
method: 'POST', credentials: 'include', body: formData
|
||||
});
|
||||
const result = await res.json();
|
||||
if (!res.ok) throw new Error(result.error || 'Virhe');
|
||||
// Lisää Markdown-kuvatagi editoriin
|
||||
const ta = document.getElementById('guide-form-content');
|
||||
const pos = ta.selectionStart;
|
||||
const mdImg = ``;
|
||||
ta.value = ta.value.substring(0, pos) + mdImg + ta.value.substring(ta.selectionEnd);
|
||||
ta.focus();
|
||||
ta.selectionStart = ta.selectionEnd = pos + mdImg.length;
|
||||
} catch (err) { alert(err.message); }
|
||||
e.target.value = ''; // nollaa input
|
||||
});
|
||||
|
||||
// Kategorianhallinta
|
||||
document.getElementById('btn-manage-guide-cats')?.addEventListener('click', () => {
|
||||
renderGuideCatList();
|
||||
|
||||
Reference in New Issue
Block a user