Skip to main content

Module markdown

Module markdown 

Source
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 ![alt](src). 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("&lt;script&gt;"));
assert!(!html.contains("<script>"));

Structs§

MdCtx
Link bases for relative targets: images resolve against raw_base, links against blob_base (JSS passes …/raw/<ref> and …/blob/<ref>).

Functions§

render
Render src with empty link bases.
render_with
Render src to HTML with link bases from ctx.
safe_href
Screen a link / image target. Absolute http(s) and #fragment targets 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 onto base.