diff --git a/public/js/md.js b/public/js/md.js new file mode 100644 index 0000000..1177564 --- /dev/null +++ b/public/js/md.js @@ -0,0 +1,41 @@ +/* md.js — tiny, safe markdown subset for user-authored copy. + * Supports: # headings, **bold**, *italic*, [links](url), - lists, blank-line paragraphs. + * Everything is HTML-escaped FIRST, so authored text can never inject markup. + */ +const esc = (s) => String(s) + .replace(/&/g, '&').replace(//g, '>') + .replace(/"/g, '"').replace(/'/g, '''); + +export function renderMarkdown(src) { + const lines = esc(src || '').split(/\r?\n/); + const out = []; + let para = [], list = null; + + const flushPara = () => { if (para.length) { out.push(`
${inline(para.join(' '))}
`); para = []; } }; + const flushList = () => { if (list) { out.push(`