Black Friday30% off · BLACKFRIDAY30–d––h––m
CommonMark vs. GitHub Flavored Markdown vs. MDX: A Practical Specification Guide
Nov 26, 2026

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

CapabilityCommonMark 0.31GitHub Flavored Markdown (GFM)MDX (v3)
Strict formal specificationYes (600+ test cases)Yes (strict superset of CommonMark)Yes (JSX + ESM over Markdown)
Pipe tables (| col |)NoYesVia remark-gfm plugin
Task lists (- [x])NoYesVia remark-gfm plugin
Strikethrough (~~text~~)NoYesVia remark-gfm plugin
Autolinks (bare URLs)Only <https://...>Bare https://... & emailsVia remark-gfm plugin
Raw inline HTMLAllowed (pass-through)Allowed, with disallowed-tag filterReplaced by strict JSX
Interactive componentsNoNoYes (import + <Component />)
Safe for untrusted user input?Yes, with HTML sanitizerYes, with HTML sanitizerNo — 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:

  1. 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).
  2. 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: #Heading is a literal paragraph in CommonMark, whereas # Heading is 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).

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 variable foo unless 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 treat 10 and as a math expression.
  • Mermaid Diagrams: Fenced code blocks labeled ```mermaid rendered 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:

  1. Parse raw Markdown into an Abstract Syntax Tree (mdast).
  2. Transform with explicit plugins (remark-gfm, remark-math) so behavior is documented and reproducible.
  3. Convert to HTML AST (remark-rehype) and sanitize (rehype-sanitize) whenever content originates from external users or LLMs.
  4. 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.

Newsletter

Join the community

Subscribe to our newsletter for the latest news and updates