RunTheTests
/

CSV to Markdown Table

Turn a CSV into a Markdown table, with pipes escaped properly.

What you paste

Parsed in your browser — never uploaded

How this reads your output

The CSV is parsed properly rather than split on commas, so quoted fields containing commas or newlines survive intact. Column widths are then measured across every row and the output is padded so the source is readable in a plain text editor. Any pipe character inside a cell is escaped, because an unescaped one splits the cell in two and silently shifts every column after it.

What the results mean

Cells containing a pipe
Escaped automatically. Left alone they would split the cell, giving the row more columns than the header and losing data in most renderers.
Problems found
Ragged rows, unterminated quotes and duplicate headers in the source. Worth fixing before converting rather than after.
Padding
Cosmetic only. No renderer requires aligned columns, but anyone reviewing the raw file will thank you.

Common problems and fixes

The table renders with columns out of alignment
Check for a row with a different number of fields from the header, which the problems count above will show. Renderers pad short rows and drop extra cells from long ones, so a single ragged row shifts everything after it without any error appearing.
Line breaks inside a cell break the table
They are converted to a line break tag, since Markdown tables cannot hold multiple lines in a cell. If the renderer has HTML disabled that tag appears literally, in which case replace the newlines with a separator such as a semicolon before converting.

Frequently asked questions

Do the columns need to be aligned in the source?

No. Renderers care only about the pipes and the separator row, so a table with no padding at all works identically. Alignment is for the humans reading the file in a text editor or a pull request.

How do I set column alignment?

Add a colon to the separator row: a leading colon aligns left, a trailing colon aligns right, and both centres. Most renderers support it, though it is an extension rather than part of the original specification.

Why does my table not render at all?

Almost always a missing blank line before the table, or a separator row that does not match the header column count. Tables are also an extension, so a strict CommonMark renderer without the extension enabled will show the raw pipes.

Put this on your own site

Free to embed, no attribution required beyond the source link the frame carries itself. It runs entirely in your visitor's browser, sets no cookies and loads no third-party script.

Embed code
<iframe src="https://runthetests.com/embed/csv-to-markdown-table/" width="100%" height="720" style="border:1px solid #e5e5e5;border-radius:8px" title="CSV to Markdown Table" loading="lazy"></iframe>

Preview it at https://runthetests.com/embed/csv-to-markdown-table/. Embedded pages are marked noindex, so yours stays the canonical copy — not this one.

More in Data