sigildocs

(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

ElementSyntax
Headers# H1 through ###### H6
ParagraphsBlank-line separated text
Code blocksFenced (```) or indented (4 spaces)
Blockquotes> quoted text
Unordered lists- item, * item, + item
Ordered lists1. item, 2. item
Horizontal rule---, ***, ___
Tables`colcol` with separator
Inline code` code `
Bold**bold** or __bold__
Italic*italic* or _italic_
Links[text](url)
Images![alt](src)

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->linesprocedure

Split string into lines.

Parse a YAML-style key: value line.

Returns (key . value) or #f.

Parse a YAML value (string, number, or boolean).

Parse 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-blocksprocedure

Parse Markdown block elements from lines.

Returns a list of block structures (headers, paragraphs, code blocks, lists, etc.) that can be converted to SXML.

parse-inlineprocedure

Parse 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"))

Parse 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"))

Parse 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...") ...)