packages

markdown

CommonMark subset to HTML: ATX headings (GitHub ids), paragraphs, fenced code, block quotes (GitHub callouts), nested lists, GFM tables, thematic breaks, <div> / <section> HTML blocks, footnote markers, and the inline forms (code, emphasis, strikethrough, links, images, autolinks, entities, escapes, hard breaks).

Structs

HeadingSource

pub struct Heading

A heading of the document, in order.

  • pub level: i32§

    Source

    1 to 6.

  • pub id: str§

    Source

    The id attribute (GitHub's anchor, -1, -2 .. on repeats).

  • pub text: str§

    Source

    Plain text (tags dropped).

DocSource

pub struct Doc

A rendered document.

OptionsSource

pub struct Options

How to render. Every field has a default: Options { link: .. }.

  • Source

    Maps a link / image destination as written to the emitted href / src (escaped by the renderer). Default: as written.

  • pub code: fn(str, str) -> (str | none) = |_lang§

    Source

    HTML for the body of a fenced code block, from the info string's first word ("" if none) and the raw code; none escapes the code as is. Goes inside <pre><code class="language-..">. Default: always none.

  • pub callout: fn(str) -> str = |kind| if kind == "note" { "Note" } else if kind == "tip" { "Tip" } else if kind == "important" { "Important" } else if kind == "warning" { "Warning" } else if kind == "caution" { "Caution" } else { kind }§

    Source

    Title of a > [!KIND] callout from the lowercased kind (escaped by the renderer). Default: Note, Tip, Important, Warning, Caution, else the kind.

Functions

renderSource

pub fn render(src: str, opts: Options | none = none) -> Doc

Markdown from a trusted source as HTML: <div> / <section> blocks pass through.

render_untrustedSource

pub fn render_untrusted(src: str, opts: Options | none = none) -> Doc

Markdown from anywhere (READMEs) as HTML: HTML blocks are text, and a link or image whose (mapped) destination has a scheme other than http, https or mailto points to #.

escSource

pub fn esc(s: str) -> str

strip_tagsSource

pub fn strip_tags(html: str) -> str

Text of an HTML fragment: tags dropped, the basic entities decoded.

slugSource

pub fn slug(text: str) -> str

GitHub's heading anchor: lowercase, keep letters / digits / - / _, spaces become -.