dashboard: render markdown file previews in the side panel

clicking a .md / .markdown path reference now opens a marked-rendered
view in the slide-in panel instead of raw text; other files stay raw
in a <pre>. serves the vendored marked bundle at /static/marked.js and
scopes a .md stylesheet to the panel body.
This commit is contained in:
müde 2026-05-20 11:01:16 +02:00
parent f13c3dff8f
commit 0c62bbf1cd
4 changed files with 67 additions and 4 deletions

View file

@ -85,13 +85,25 @@
return text;
}
// Lazy-load `path` from /api/state-file into the side panel.
// Markdown files render through `marked` into a `.md` block; every
// other file stays raw text in a <pre>.
async function openFilePanel(path) {
const pre = el('pre', { class: 'path-preview-body' }, '(fetching…)');
Panel.open('↳ ' + path, pre);
const isMd = /\.(md|markdown)$/i.test(path);
const view = isMd
? el('div', { class: 'md' })
: el('pre', { class: 'path-preview-body' });
view.textContent = '(fetching…)';
Panel.open('↳ ' + path, view);
try {
pre.textContent = await fetchStateFile(path);
const text = await fetchStateFile(path);
if (isMd && window.marked && typeof window.marked.parse === 'function') {
marked.setOptions({ breaks: true, gfm: true });
view.innerHTML = marked.parse(text);
} else {
view.textContent = text;
}
} catch (e) {
pre.textContent = 'error: ' + (e.message || e);
view.textContent = 'error: ' + (e.message || e);
}
}
function makePathLink(path) {