feat(web): Markdown editor with toolbar limited to what is rendered

Legal documents, maintenance and status page descriptions get an editor
with a toolbar of the formatting their field supports, keyboard
shortcuts, list continuation, a character count and a preview rendered
by the server. Images are no longer rendered: an external image on a
status page would hand every visitor's address to its host, so the
editor offers none. Editor behavior is tested in a headless browser
when Chromium is available.

Closes #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 10:50:53 +01:00
1 parent 532bb0d1b0
commit d7126b1e2c
20 files changed
+1206 -602

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
<!doctype html><html><body data-msg-network="net">
<div data-md-editor>
<div data-md-toolbar>
<button type="button" data-md-action="bold"></button><button type="button" data-md-action="italic"></button>
<button type="button" data-md-action="link"></button><button type="button" data-md-action="ul"></button>
<button type="button" data-md-action="ol"></button><button type="button" data-md-action="heading"></button>
</div>
<button type="button" data-md-tab="write"></button><button type="button" data-md-tab="preview"></button>
<textarea maxlength="100"></textarea>
<div data-md-preview hidden data-empty="empty"></div><span data-md-count></span>
</div>
<pre id="out"></pre>
<script>
window.axios = { create: () => ({ interceptors: { request: { use() {} } }, post: async (u, b) => ({ data: { html: "<p>R:" + b.markdown + "</p>" } }) }) };
</script>
<script src="../assets/app.js"></script>
<script>
(async () => {
const ta = document.querySelector("textarea"), out = [];
const act = (a) => document.querySelector(`[data-md-action="${a}"]`).click();
const key = (k, mods = {}) => ta.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true, ...mods }));
const set = (v, s, e) => { ta.value = v; ta.setSelectionRange(s, e ?? s); };
const check = (name, got, want) => out.push((got === want ? "PASS " : "FAIL ") + name + (got === want ? "" : " got=" + JSON.stringify(got) + " want=" + JSON.stringify(want)));
set("hello world", 6, 11); act("bold"); check("bold wraps selection", ta.value, "hello **world**");
check("selection kept", ta.value.slice(ta.selectionStart, ta.selectionEnd), "world");
act("bold"); check("bold toggles off", ta.value, "hello world");
set("", 0); key("i", { ctrlKey: true }); check("ctrl+i placeholder", ta.value, "_text_");
set("", 0); key("s", { ctrlKey: true }); check("unavailable shortcut ignored", ta.value, "");
set("docs", 0, 4); act("link"); check("link", ta.value, "[docs](https://)");
check("url selected", ta.value.slice(ta.selectionStart, ta.selectionEnd), "https://");
set("a\nb", 0, 3); act("ul"); check("list prefixes lines", ta.value, "- a\n- b");
ta.setSelectionRange(0, ta.value.length); act("ul"); check("list toggles off", ta.value, "a\nb");
set("a\nb", 0, 3); act("ol"); check("numbered", ta.value, "1. a\n2. b");
set("- one", 5); key("Enter"); check("enter continues list", ta.value, "- one\n- ");
key("Enter"); check("enter on empty item ends list", ta.value, "- one\n");
set("3. x", 4); key("Enter"); check("numbers increment", ta.value, "3. x\n4. ");
set("Title", 2); act("heading"); check("heading", ta.value, "## Title");
set("abc", 3); ta.dispatchEvent(new Event("input")); check("count", document.querySelector("[data-md-count]").textContent, "3 / 100");
document.querySelector('[data-md-tab="preview"]').click(); await new Promise((r) => setTimeout(r, 50));
check("preview from server", document.querySelector("[data-md-preview]").innerHTML, "<p>R:abc</p>");
check("textarea hidden in preview", ta.hidden, true);
check("toolbar disabled in preview", document.querySelector('[data-md-action="bold"]').disabled, true);
document.querySelector('[data-md-tab="write"]').click(); check("back to write", ta.hidden, false);
document.getElementById("out").textContent = out.join("\n");
})();
</script></body></html>