Skip to content
GFM Tables
step 1/5

Reading — step 1 of 5

Read

~1 min readProduction Concerns

GFM Tables

GitHub Flavored Markdown extends CommonMark with pipe tables:

| Name  | Age | City    |
|-------|-----|---------|
| Alice |  30 | NYC     |
| Bob   |  25 | Berlin  |

renders to a <table> with <thead> and <tbody>.

Anatomy

  • Header row — first row with |-separated cells.
  • Separator row — second row of --- (optionally with leading/trailing : for alignment). This is what disambiguates a table from a plain paragraph that happens to contain |.
  • Body rows — subsequent |-separated rows until a blank line.

Alignment The separator cells control column alignment:

  • --- — default (left)
  • :--- — left (explicit)
  • ---: — right
  • :---: — center
| left | center | right |
|:-----|:------:|------:|
|  a   |   b    |   c   |

Implementation A pragmatic detector:

python

Tables are NOT in the CommonMark core. They are a GFM extension. Most modern parsers (cmark-gfm, markdown-it, pulldown-cmark) implement them behind a flag. A complete parser should:

  1. Detect the table during block parsing (header + separator pattern).
  2. Split each row by |, trim each cell.
  3. Parse alignment from the separator.
  4. Inline-parse each cell's content.

Edge case: a single | in a paragraph (e.g. a | b) is NOT a table because there is no separator row. The detector must require BOTH the pipe row AND the matching separator.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…