
CommonMark vs. GitHub Flavored Markdown vs. MDX: A Practical Specification Guide
Understand the real technical differences between CommonMark, GitHub Flavored Markdown (GFM), and MDX—covering AST parsing, tables, math, security sanitization, and when to choose each dialect.
Almost every developer writes Markdown daily, yet few realize there is no single "Markdown" standard. A document that renders cleanly in a GitHub README can break completely inside a static site generator, a Jira ticket, or a note-taking app.
Those discrepancies exist because John Gruber's original 2004 Markdown specification intentionally left many edge cases undefined—nested lists, indented code inside blockquotes, raw HTML interleaving, and table syntax. Over the past decade, three distinct dialects have emerged as the backbone of modern web publishing: CommonMark, GitHub Flavored Markdown (GFM), and MDX.
Feature Comparison at a Glance
| Capability | CommonMark 0.31 | GitHub Flavored Markdown (GFM) | MDX (v3) |
|---|---|---|---|
| Strict formal specification | Yes (600+ test cases) | Yes (strict superset of CommonMark) | Yes (JSX + ESM over Markdown) |
Pipe tables (| col |) | No | Yes | Via remark-gfm plugin |
Task lists (- [x]) | No | Yes | Via remark-gfm plugin |
Strikethrough (~~text~~) | No | Yes | Via remark-gfm plugin |
| Autolinks (bare URLs) | Only <https://...> | Bare https://... & emails | Via remark-gfm plugin |
| Raw inline HTML | Allowed (pass-through) | Allowed, with disallowed-tag filter | Replaced by strict JSX |
| Interactive components | No | No | Yes (import + <Component />) |
| Safe for untrusted user input? | Yes, with HTML sanitizer | Yes, with HTML sanitizer | No — executes JavaScript |
1. CommonMark: The Unambiguous Baseline
CommonMark was created to eliminate ambiguity in Markdown parsing. Its specification defines an exact two-phase parsing algorithm:
- Block structure phase: The parser reads line by line to build a tree of container blocks (blockquotes, lists) and leaf blocks (headings, paragraphs, fenced code blocks, HTML blocks).
- Inline structure phase: After the block tree is complete, the parser processes text inside leaf blocks for emphasis (
*em*), links, images, and code spans.
Because of this strict separation, CommonMark resolves classic edge cases predictably:
- Blank lines and lazy continuation: A paragraph inside a list item requires consistent indentation; otherwise, the list ends cleanly.
- Emphasis precedence: Code spans (
`a *b* c`) always take precedence over emphasis markers, so asterisks inside inline code never accidentally italicize half a paragraph. - ATX headings require a space:
#Headingis a literal paragraph in CommonMark, whereas# Headingis an<h1>.
When to choose CommonMark: When building a parser, comment system, or interchange format where strict predictability and zero extension surprises matter most.
2. GitHub Flavored Markdown (GFM): The Practical Default
GFM is a formal superset of CommonMark maintained by GitHub. It adds five extensions that technical writers rely on constantly:
Pipe Tables
| Engine | Language | Spec Compliance |
| --- | --- | --- |
| markdown-it | JavaScript | CommonMark + plugins |
| remark | JavaScript | CommonMark + remark-gfm |
| comrak | Rust | CommonMark + GFM |
| goldmark | Go | CommonMark + GFM |Two table rules trip people up frequently:
- The delimiter row (
| --- |) must have the exact same column count as the header row, or the entire block falls back to plain paragraph text. - Pipe characters inside cell values must be escaped as
\|(even inside inline code spans in some parsers).
Task Lists, Strikethrough, and Extended Autolinks
GFM turns - [ ] and - [x] into disabled <input type="checkbox"> elements, renders ~~deleted~~ as <del>, and automatically converts bare https://example.com strings into clickable links without angle brackets.
Disallowed Raw HTML Extension
Unlike base CommonMark, GFM explicitly defines a list of raw HTML tags that are escaped before rendering—including <title>, <textarea>, <style>, <xmp>, <iframe>, <noembed>, <noframes>, <script>, and <plaintext>. Note that this filter alone is not a complete XSS defense (attributes like <img onerror="..."> still need a dedicated sanitizer such as DOMPurify or rehype-sanitize).
When to choose GFM: For READMEs, engineering specs, AI chat outputs, changelogs, and any portable documentation you expect to share across tools.
3. MDX: Markdown Compiled Into JSX
MDX is not merely a Markdown flavor—it is a compiler format that turns a .mdx file into an ES module exporting a React (or Preact/Vue/Solid) component.
import { Callout } from '@/components/callout';
## Deployment Checklist
<Callout type="warning">
Verify your `NODE_ENV` before running production migrations.
</Callout>Because MDX parses embedded markup as JSX rather than HTML, standard HTML habits break in subtle ways:
- Void tags must be self-closing:
<br>,<hr>, and<img src="...">throw a syntax error in MDX; they must be written as<br />,<hr />, and<img src="..." />. - HTML comments fail:
<!-- note -->causes a parse error. MDX requires JSX comments ({/* note */}). - Curly braces are JavaScript expressions: Writing
{foo}in prose evaluates the variablefoounless escaped as\{foo\}or wrapped in backticks. - Blank lines around blocks matter: Mixing Markdown syntax directly inside JSX tags without blank lines can prevent Markdown parsing inside the component body.
When to choose MDX: For documentation portals, product blogs, and interactive engineering guides authored by trusted developers inside a git repository. Never compile untrusted user-submitted text as MDX, because arbitrary JavaScript expressions inside {...} execute during rendering.
Common Extensions Beyond GFM
Many technical documents rely on two ecosystems that sit on top of GFM rather than inside its core spec:
- LaTeX Math (
remark-math+ KaTeX / MathJax): Inline$E = mc^2$and display$$...$$blocks. A frequent gotcha is unescaped currency signs—writing "between $10 and $20" without escaping\$causes math parsers to treat10 andas a math expression. - Mermaid Diagrams: Fenced code blocks labeled
```mermaidrendered client-side or build-time into SVG flowcharts and sequence diagrams. Because standard Markdown viewers treat unknown fence languages as plain code blocks, Mermaid degrades gracefully even in unsupported viewers.
Choosing the Right Rendering Pipeline
If you are building a web application that renders Markdown, keep your pipeline modular using the unified ecosystem (remark → rehype) or markdown-it:
- Parse raw Markdown into an Abstract Syntax Tree (mdast).
- Transform with explicit plugins (
remark-gfm,remark-math) so behavior is documented and reproducible. - Convert to HTML AST (
remark-rehype) and sanitize (rehype-sanitize) whenever content originates from external users or LLMs. - Highlight code blocks at build time (Shiki) or lazily in the browser so syntax highlighting does not bloat your initial JavaScript bundle.
FAQ
Why do my Markdown tables work on GitHub but break in another viewer?
Tables are not part of core CommonMark—they are a GitHub Flavored Markdown (GFM) extension. If the target viewer uses a strict CommonMark parser without a table plugin, the pipe syntax renders as plain text.
Is Markdown safe from XSS attacks by default?
No. Both CommonMark and GFM permit raw inline HTML, and Markdown links can contain javascript: URIs ([click](javascript:alert(1))). Always sanitize the resulting HTML with a strict allowlist sanitizer like DOMPurify or rehype-sanitize before inserting it into the DOM.
Can I convert MDX back to standard GFM?
Only partially. Standard headings, lists, and code blocks transfer directly, but custom JSX components (<Tabs>, <Callout>) and ES imports have no equivalent in plain Markdown and must be replaced with static text or HTML equivalents.
Which Markdown dialect do ChatGPT and Claude output?
Modern LLMs predominantly output GitHub Flavored Markdown extended with LaTeX math delimiters ($...$, $$...$$, or \(...\) / \[...\]) and Mermaid fenced code blocks.
Author
Founder of dochost (Xhorizon Labs LLC). Software engineer focused on web publishing, HTML and Markdown rendering pipelines, sandboxed content delivery, and AI developer workflows.
Categories
More Posts

Pastebin vs dochost: Raw Text vs a Rendered Page
When Pastebin's monospace raw text is the right call, and when you actually want your Markdown or HTML rendered as a real page at a shareable link.

How to Share Math Notes Online (With LaTeX Rendering)
Turn Markdown notes full of LaTeX equations into a clean, shareable web page — no Overleaf project, no PDF export, no screenshots of handwriting.

Share Claude's Markdown as a Clean Page
Claude answers in well-structured Markdown, but pasted into email or Slack it falls apart. Here's how to send it as a readable page instead.
Newsletter
Join the community
Subscribe to our newsletter for the latest news and updates