md
Markdown parser and HTML renderer (CommonMark subset) - parse a Markdown string into a node list covering h1–h6, fenced code blocks with language tags, unordered lists, blockquotes, horizontal rules, paragraphs, and blank lines; process inline bold (**/__), italic (*/_), inline code, and links; render the node list to an HTML string.
Load with: use md
What this module does
md parses Markdown line by line into an intermediate node list,
then renders those nodes to HTML. Inline spans (bold, italic, code, links) are
processed inside paragraph and heading text after HTML-escaping via web.esc.
Code block content is HTML-escaped but not inline-processed, preserving literal
angle brackets.
Use md.ren for a one-call parse-and-render, or use
md.prs / md.htm separately to inspect or transform
the node list before rendering.
Quick example
use md
src = "# Hello\n\nThis is **bold** and *italic* text.\n\n- item one\n- item two\n\n```js\nconsole.log('hi')\n```"
# Parse to node list
nodes = md.prs(src)
# [{t:"h",lv:1,tx:"Hello"}, {t:"br"}, {t:"p",tx:"..."}, ...]
# Render to HTML
html = md.htm(nodes)
# One-call shorthand
html = md.ren(src)
# Inline spans only
prn(md.inl("click **here** for [docs](https://example.com)"))
Functions
Parsing
mdprs(s) / md.prs(s)
Parses a Markdown string line by line. Returns a list of block nodes. Node types: {t:"h", lv, tx} (headings), {t:"p", tx} (paragraph), {t:"code", lang, tx} (fenced code block), {t:"ul", items} (unordered list), {t:"bq", tx} (blockquote), {t:"hr"} (horizontal rule), {t:"br"} (blank line).
Rendering
mdhtm(nodes) / md.htm(nodes)
Renders a parsed node list to an HTML string. Heading and paragraph text is HTML-escaped then inline-processed. Code block content is escaped only. Blank-line nodes produce no output.
mdren(s) / md.ren(s)
Convenience: parse then render in one call. Returns the HTML string.
Inline processing
mdinl(s) / md.inl(s)
Applies inline Markdown processing to a string: **bold** → <strong>, __bold__ → <strong>, *italic* → <em>, _italic_ → <em>, `code` → <code>, and [label](url) → <a href="url">.
Notes
- Implements a subset of CommonMark - no nested lists, no ordered lists, no tables, no setext headings.
- Requires
trl,txt, andweb.