Extensions

Extensions add syntax beyond the CommonMark specification. They must be explicitly enabled with enable!.

using CommonMark

Tables

Pipe-style tables from GitHub Flavored Markdown. Tables require a header row and a separator row that defines column alignment.

parser = Parser()
enable!(parser, TableRule())

ast = parser("""
| Column One | Column Two | Column Three |
|:---------- | ---------- |:------------:|
| Row `1`    | Column `2` |              |
| *Row* 2    | **Row** 2  | Column 3     |
""")
html(ast)
"<table><thead><tr><th align=\"left\">Column One</th><th align=\"left\">Column Two</th><th align=\"center\">Column Three</th></tr></thead><tbody><tr><td align=\"left\">Row <code>1</code></td><td align=\"left\">Column <code>2</code></td><td align=\"center\"></td></tr><tr><td align=\"left\"><em>Row</em> 2</td><td align=\"left\"><strong>Row</strong> 2</td><td align=\"center\">Column 3</td></tr></tbody></table>"

Alignment is set with colons in the separator: :--- left, ---: right, :---: center. Cells can contain inline formatting. Escape literal pipes with backslashes.

Admonitions

Callout boxes for notes, warnings, tips, and other highlighted content. Common in technical documentation.

parser = Parser()
enable!(parser, AdmonitionRule())

ast = parser("""
!!! note "Custom Title"
    This is an admonition block.

!!! warning
    Title defaults to category name.
""")
html(ast)
"<div class=\"admonition note\"><p class=\"admonition-title\">Custom Title</p>\n<p>This is an admonition block.</p>\n</div><div class=\"admonition warning\"><p class=\"admonition-title\">Warning</p>\n<p>Title defaults to category name.</p>\n</div>"

The category (note, warning, tip, etc.) determines styling. An optional quoted string overrides the title. Content must be indented by 4 spaces.

Footnotes

Reference-style footnotes that collect at the end of the document. Useful for citations, asides, and additional context without interrupting flow.

parser = Parser()
enable!(parser, FootnoteRule())

ast = parser("""
Here is a footnote reference[^1].

[^1]: This is the footnote content.
""")
html(ast)
"<p>Here is a footnote reference<a href=\"#footnote-1\" class=\"footnote\">1</a>.</p>\n<div class=\"footnote\" id=\"footnote-1\"><p class=\"footnote-title\">1</p>\n<p>This is the footnote content.</p>\n</div>"

Footnote identifiers can be any word or number. Definitions can appear anywhere in the document and will be collected at the end.

Typography

Converts ASCII punctuation to proper typographic characters. Makes documents look more polished without requiring special input.

parser = Parser()
enable!(parser, TypographyRule())

ast = parser("\"Hello\" -- Pro tip... use 'single quotes' too --- or not.")
html(ast)
"<p>“Hello” – Pro tip… use ‘single quotes’ too — or not.</p>\n"

Conversions: straight quotes to curly quotes, ... to ellipsis, -- to en-dash, --- to em-dash. Disable specific conversions with keyword arguments:

enable!(parser, TypographyRule(double_quotes=false, dashes=false))

Math

LaTeX math expressions for technical and scientific documents.

Julia-style (double backticks)

Uses double backticks for inline math, matching Julia's docstring convention. Display math uses fenced code blocks with math as the language.

parser = Parser()
enable!(parser, MathRule())

ast = parser("Inline ``E = mc^2`` math.")
html(ast)
"<p>Inline <span class=\"math tex\">\\(E = mc^2\\)</span> math.</p>\n"

Display math with fenced blocks:

ast = parser("""
```math
\\int_0^\\infty e^{-x^2} dx
```
""")
html(ast)
"<div class=\"display-math tex\">\\[\\int_0^\\infty e^{-x^2} dx\\]</div>"

Dollar-style

Traditional LaTeX syntax with single $ for inline and double $$ for display. More familiar to users coming from LaTeX or other markdown flavors.

parser = Parser()
enable!(parser, DollarMathRule())

ast = parser("Inline \$E = mc^2\$ math.")
html(ast)
"<p>Inline <span class=\"math tex\">\\(E = mc^2\\)</span> math.</p>\n"

Attributes

Attach IDs, classes, and arbitrary key-value pairs to elements. Useful for styling, linking, and integrating with JavaScript.

parser = Parser()
enable!(parser, AttributeRule())

ast = parser("""
{#my-id .highlight}
# Heading
""")
html(ast)
"<h1 class=\"highlight\" id=\"my-id\"><a href=\"#my-id\" class=\"anchor\"></a>Heading</h1>\n"

Block attributes go above the target element. Inline attributes go after:

ast = parser("*text*{.important}")
html(ast)
"<p><em class=\"important\">text</em></p>\n"

CSS shorthand: #foo expands to id="foo", .bar expands to class="bar".

Strikethrough

Marks deleted or outdated text. Renders as <del> in HTML.

parser = Parser()
enable!(parser, StrikethroughRule())

ast = parser("~~deleted text~~")
html(ast)
"<p><del>deleted text</del></p>\n"

Subscript

Chemical formulas, mathematical notation, and other subscripted text.

parser = Parser()
enable!(parser, SubscriptRule())

ast = parser("H~2~O")
html(ast)
"<p>H<sub>2</sub>O</p>\n"

Can be combined with StrikethroughRule since they use different tilde counts (single vs double).

Superscript

Exponents, ordinals, and other superscripted text.

parser = Parser()
enable!(parser, SuperscriptRule())

ast = parser("x^2^")
html(ast)
"<p>x<sup>2</sup></p>\n"

Task Lists

Interactive checklists from GitHub Flavored Markdown. Useful for todo lists and progress tracking.

parser = Parser()
enable!(parser, TaskListRule())

ast = parser("""
- [ ] Unchecked
- [x] Checked
""")
html(ast)
"<ul>\n<li><input type=\"checkbox\" disabled> Unchecked</li>\n<li><input type=\"checkbox\" disabled checked> Checked</li>\n</ul>\n"

GitHub Alerts

Styled callouts matching GitHub's markdown alerts. Similar to admonitions but with GitHub's specific syntax and categories.

parser = Parser()
enable!(parser, GitHubAlertRule())

ast = parser("""
> [!NOTE]
> Useful information.

> [!WARNING]
> Important warning.
""")
html(ast)
"<div class=\"github-alert note\"><p class=\"github-alert-title\">Note</p>\n<p>Useful information.</p>\n</div>\n<div class=\"github-alert warning\"><p class=\"github-alert-title\">Warning</p>\n<p>Important warning.</p>\n</div>\n"

Supported types: NOTE, TIP, IMPORTANT, WARNING, CAUTION.

Fenced Divs

Generic containers from Pandoc. Wrap arbitrary content in a div with classes and attributes. Useful for custom styling and semantic markup.

parser = Parser()
enable!(parser, FencedDivRule())

ast = parser("""
::: warning
This is a warning.
:::
""")
html(ast)
"<div class=\"warning\">\n<p>This is a warning.</p>\n</div>\n"

Divs can be nested by using more colons for outer fences.

Front Matter

Structured metadata at the start of a document. Commonly used for titles, authors, dates, and configuration in static site generators.

using YAML

parser = Parser()
enable!(parser, FrontMatterRule(yaml=YAML.load))

ast = parser("""
---
title: My Document
author: Jane Doe
---

Content here.
""")
frontmatter(ast)
Dict{String, Any} with 2 entries:
  "author" => "Jane Doe"
  "title"  => "My Document"

Delimiters determine format: --- for YAML, +++ for TOML, ;;; for JSON. Pass the appropriate parser function for each format you want to support.

Citations

Academic-style citations with Pandoc syntax. Requires bibliography data to be passed to the writer.

enable!(parser, CitationRule())
According to @smith2020, this is true.

Bracketed: [@smith2020; @jones2021]

Auto Identifiers

Automatically generates IDs for headings based on their text. Enables linking directly to sections.

parser = Parser()
enable!(parser, AutoIdentifierRule())

ast = parser("# My Heading")
html(ast)
"<h1 id=\"my-heading\"><a href=\"#my-heading\" class=\"anchor\"></a>My Heading</h1>\n"

IDs are slugified: lowercased, spaces become hyphens, special characters removed. Duplicate headings get numeric suffixes.

Preserves reference-style link syntax in the AST instead of resolving it during parsing. Enables accurate markdown roundtripping.

enable!(parser, ReferenceLinkRule())

Raw Content

Pass format-specific content through unchanged. Useful for embedding LaTeX commands, HTML widgets, or other content that shouldn't be processed.

enable!(parser, RawContentRule())

The format name (html, latex, typst) is specified in the attribute. The parser automatically determines inline vs block from context.

Inline: `<span>html</span>`{=html}

Block:
```{=latex}
\textbf{LaTeX}
```

Default formats: html, latex, typst. Custom formats can be added by passing type mappings to RawContentRule.