CommonMark-style Markdown parser for Sigil
sigil-markdown
A CommonMark-style Markdown parser for Sigil with YAML front matter support. Produces SXML output for use with (sigil sxml).
Features
- CommonMark-style Markdown parsing
- YAML front matter extraction
- SXML AST output
- PEG-based inline parsing
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 | ` |
| Inline code | `code` |
| Bold | **bold** or __bold__ |
| Italic | *italic* or _italic_ |
| Links | [text](url) |
| Images |  |
Usage
(import (sigil markdown))
;; Parse a Markdown string to SXML
(markdown->sxml "# Hello\n\nWorld")
;; => (document (h1 "Hello") (p "World"))
;; Parse a Markdown file
(markdown-file->sxml "README.md")
;; Front matter is parsed into SXML attributes
(markdown->sxml "---\ntitle: Hello\n---\n\n# Content")
;; => (document (@ (title "Hello")) (h1 "Content"))
API
markdown->sxml- Parse a Markdown string to SXMLmarkdown-file->sxml- Parse a Markdown file to SXMLparse-front-matter- Extract YAML front matter from textparse-blocks- Lower-level block parserparse-inline- Lower-level inline parser
Dependencies
- sigil-stdlib - Sigil standard library
- sigil-peg - PEG parsing library
Development
sigil deps install
sigil build
sigil test
License
BSD-3-Clause