Expand description
A small, bounded, escape-first Markdown renderer.
Behaviour follows the JSS forge lib/markdown.js (renderMarkdown)
grammar, cited by name only; the code is original and uses no regex
engine. The design is structurally XSS-safe: the raw source is
HTML-escaped with crate::request::esc before any tag is introduced,
there is no HTML passthrough, and link / image targets are screened by
safe_href (no javascript:, data:, protocol-relative or traversing
targets).
Blocks: #..###### headings, fenced code, > quotes, -/* and 1.
lists, GFM tables with per-column alignment, paragraphs. Inline: code
spans, **strong**, *em* / _em_, [text](href) and .
No nesting.
§Examples
use solid_pod_rs_forge::markdown::render;
let html = render("# Hi\n\nsome **bold** and `code`\n\n<script>x</script>");
assert!(html.contains("<h1>Hi</h1>"));
assert!(html.contains("<strong>bold</strong>"));
assert!(html.contains("<script>"));
assert!(!html.contains("<script>"));Structs§
- MdCtx
- Link bases for relative targets: images resolve against
raw_base, links againstblob_base(JSS passes…/raw/<ref>and…/blob/<ref>).
Functions§
- render
- Render
srcwith empty link bases. - render_
with - Render
srcto HTML with link bases fromctx. - safe_
href - Screen a link / image target. Absolute
http(s)and#fragmenttargets pass; protocol-relative and any other scheme are refused; a relative path with an empty or..segment (or a leading/) is refused, otherwise it is joined ontobase.