> codebench_TOOL: HomeLOCAL-ONLY⌘K Switch

Markdown Tables from CSV: How to Escape Pipes on GitHub

Turn a small CSV into a GitHub Flavored Markdown table, keep literal pipes inside cells, and align columns without changing row order.

·3 min readAbout the maintainer

A CSV is easy to export and awkward to read in a pull request. For a small set of results, a Markdown table gives reviewers something they can scan without opening a spreadsheet. The conversion is simple until a value contains a pipe, a quoted comma, or a line break. Those characters mean different things in the two formats.

What makes a Markdown table

Tables are an extension in GitHub Flavored Markdown (GFM), not part of core CommonMark. A GFM table starts with a header row and a delimiter row. Each has to describe the same number of columns. The lines after that are data rows.

Leave a blank line before the table when it follows a paragraph. Outer pipes are optional in GFM, but keeping them makes the column boundaries easier to see. The source does not have to line up in a text editor; the renderer uses pipes, not spaces, to find the columns.

Convert a small CSV

Suppose you have three service checks:

Service,Status,Latency (ms)
search,read|write,120
cache,ready,8
api,ready,35
  1. Open the Markdown Table Generator, choose Import CSV, paste the sample, and click Import. The first line becomes the header, and the remaining lines keep their order.
  2. Leave Service at L. Click the Status header's alignment button once to reach C, and click the Latency (ms) button twice to reach R.
  3. Click Copy and paste the result into Markdown Preview. There should be three columns, with read|write entirely inside the first row's status cell.

The generator produces this Markdown:

| Service | Status      | Latency (ms) |
| :------ | :---------: | -----------: |
| search  | read\|write | 120          |
| cache   | ready       | 8            |
| api     | ready       | 35           |

CodeBench's table importer is a simple delimiter splitter. It can detect plain comma- or tab-separated data, but it does not honor CSV quotes. A value like "Albany, NY" will split at the comma; a quoted newline becomes a new row. For quoted data, inspect it first with CSV to JSON, which handles quoted commas and newlines. Then enter the parsed values in the table grid, replacing embedded line breaks with spaces if a single line will do. Turning every comma into a pipe won't work.

Escape content and align columns

In CSV, quotes can protect a comma. In a GFM table, use a backslash to keep a literal pipe inside a cell: read\|write. The generator adds that escape for you, so enter read|write as raw text. If you edit the Markdown by hand, escape pipes even inside inline code spans in GFM tables. Backticks alone do not keep a pipe from being treated as a column boundary.

The generator escapes pipes; it does not turn all Markdown syntax into literal text. For example, a value like *draft* can render as emphasis. Preview the output if your source data contains Markdown punctuation.

The colons in the delimiter row control horizontal alignment:

  • :--- aligns left, useful for names and prose.
  • :---: centers, useful for short status labels.
  • ---: aligns right, useful for comparing numbers.

Alignment does not sort the rows. If you want lowest latency first, sort the source numerically before importing. In this example the desired order would be 8, 35, 120; a text sort would put 120 first. A normal GFM table does not add click-to-sort headers.

Summary

  • Use a header and a matching delimiter row, with a blank line before the table.
  • Import simple CSV directly. Parse quoted CSV before moving its values into the grid.
  • Write \| for a literal pipe in the Markdown source. Use colons for alignment and sort the source separately.

For more examples, see GitHub's guide to organizing information with tables and RFC 4180 for CSV quoting conventions.

#markdown#gfm#csv#github
> codebench $Ctrl+Enter Run