(sigil markdown)
(sigil markdown) - Markdown Parser
Parses Markdown text into an SXML AST for use with (sigil sxml). Supports CommonMark-style syntax with YAML front matter.
Basic Usage
(import (sigil markdown))
(markdown->sxml "# Hello\n\nWorld")
; => (document (h1 "Hello") (p "World"))
(markdown-file->sxml "README.md")Supported Syntax
| Element | Syntax | |||
|---|---|---|---|---|
| Headers | # H1 through ###### H6 | |||
| Paragraphs | Blank-line separated text | |||
| Code blocks | Fenced (```) or indented (4 spaces) | |||
| Blockquotes | > quoted text | |||
| Unordered lists | - item, * item, + item | |||
| Ordered lists | 1. item, 2. item | |||
| Horizontal rule | ---, ***, ___ | |||
| Tables | ` | col | col | ` with separator |
| Inline code | ` code ` | |||
| Bold | **bold** or __bold__ | |||
| Italic | *italic* or _italic_ | |||
| Links | [text](url) | |||
| Images |  |
Front Matter
YAML-style front matter is parsed into SXML attributes:
(markdown->sxml "---\ntitle: Hello\n---\n\n# Content")
; => (document (@ (title "Hello")) (h1 "Content"))Exports
string->linesprocedureSplit string into lines.
parse-yaml-lineprocedureParse a YAML-style key: value line.
Returns (key . value) or #f.
parse-yaml-valueprocedureParse a YAML value (string, number, or boolean).
parse-front-matterprocedureParse YAML front matter from lines.
Returns (front-matter . remaining-lines) where front-matter is an alist of metadata, or (#f . lines) if no front matter is present.
(parse-front-matter '("---" "title: Hello" "---" "" "# Content"))
; => (((title . "Hello")) "" "# Content")parse-blocksprocedureParse Markdown block elements from lines.
Returns a list of block structures (headers, paragraphs, code blocks, lists, etc.) that can be converted to SXML.
parse-inlineprocedureParse inline Markdown elements from text.
Handles code spans, bold, italic, links, and images. Returns a list of strings and SXML elements.
(parse-inline "Hello **world**")
; => ("Hello " (strong "world"))markdown->sxmlprocedureParse a Markdown string to an SXML document.
Returns a document element containing the parsed content. If YAML front matter is present, it becomes attributes on the document element.
(markdown->sxml "# Hello\n\nWorld")
; => (document (h1 "Hello") (p "World"))
(markdown->sxml "---\ntitle: Test\n---\n\n# Content")
; => (document (@ (title "Test")) (h1 "Content"))markdown-file->sxmlprocedureParse a Markdown file to an SXML document.
Reads the file contents and parses as Markdown.
(markdown-file->sxml "README.md")
; => (document (h1 "Project Name") (p "Description...") ...)