feat(viewer): render Markdown with marked#8
Conversation
The serve viewer used a hand-rolled line-based renderer that only handled headings, fenced code, and flat `- ` items (emitted as paragraphs). Lists, nested lists, tables, bold/italic, blockquotes, horizontal rules, and multi-line paragraphs were unsupported, so almanac pages rendered poorly. Replace it with `marked` v18, vendored at viewer/vendor/marked.esm.js (the viewer ships as static assets with no build step) and wrapped by viewer/markdown.js. Behaviour preserved from the old renderer: - `[[wikilink]]` resolution via a custom inline extension - `[text](pages/x.md)` links resolved to in-app page routes, http(s) links opened in a new tab, unresolvable targets rendered as plain text - raw inline/block HTML escaped rather than passed through - the first `# heading` keeps its decorated title + summary + ornament; other level-1 headings demoted to h2 Adds ca-prose CSS for the newly-rendered elements (lists, tables, blockquotes, hr, strong/em, task-list checkboxes, images).
|
Thanks for this, this is a strong direction. The old viewer renderer was intentionally tiny, but it now underserves real Almanac pages pretty badly, so moving markdown rendering into a dedicated wrapper around I’d like to get two things tightened before merge:
Overall: feature direction looks useful and worth merging once the image policy and renderer tests are in place. |
What and why
The
serveviewer used a hand-rolled, line-based Markdown renderer that only handled headings, fenced code, and flat-items (emitted as paragraphs). Lists, nested lists, tables,**bold**/*italic*, blockquotes,---, and multi-line paragraphs were unsupported — almanac pages rendered poorly.Change
Replace the renderer with marked v18, vendored at
viewer/vendor/marked.esm.js(the viewer ships as static assets with no build step) and wrapped byviewer/markdown.js.Behaviour preserved from the old renderer:
[[wikilink]]resolution via a custom inline extension[text](pages/x.md)links resolved to in-app page routes;http(s)links opened in a new tab; unresolvable targets rendered as plain text# headingkeeps its decorated title + summary + ornament; other level-1 headings demoted to h2Adds
.ca-proseCSS for the newly-rendered elements (lists, tables, blockquotes, hr, strong/em, task-list checkboxes, images).Testing
viewer/markdown.jsexercised with a Node render test across all paths (title, wikilink, page-link, dead-link, external link, nested lists, tables, blockquote, escaped<script>, code blocks).test/viewer-ui-assets.test.tsupdated for the new architecture.npm test— 479/479 passing,tsc --noEmitclean.