Escape Pipes in a Markdown Table When Converting CSV
A pipe is ordinary text in comma-delimited CSV. In a Markdown table, a bare pipe separates columns. Escape the pipe in the Markdown output so a value such as A|B still occupies one cell.
Worked example
CSV with a pipe and a quoted comma
Team,Tag,Note Blue,A|B,"Ordered, not ranked" Amber,C,Waitlist
Steps
- Start with the example CSV. Keep the comma inside the quoted field on the first row; it is part of the value, not a column separator.
- Convert the CSV. The generated Markdown should prefix the pipe in A|B with a backslash. If you are editing the table by hand, escape the cell's pipe and leave the column separators alone.
- Preview the table in the reader that will publish it. The header and both body rows should have three columns, and the first tag should display as A|B.
What to check
- Use a CSV parser rather than splitting the source on every comma. Fixing a Markdown escape cannot recover a value that got split during CSV parsing.
- Preview cells that include an existing backslash before a pipe. Markdown treats backslashes as escapes, so those values need a separate rendering check.