Data Formats
How to Escape Pipes in Markdown Tables
Inside a Markdown table, an unescaped pipe usually separates cells. Prefix a literal pipe with a backslash so it remains part of the cell content.
Published
Why a pipe creates another cell
The table extension treats pipes as column delimiters. A literal pipe without an escape can shift later values into unexpected columns or make the row inconsistent with the header.
| Expression | Meaning |
| --- | --- |
| yes|no | Either value |Escape a pipe in ordinary cell text
Place one Markdown backslash immediately before the pipe. The source keeps the structural delimiter separate from the character displayed inside the cell.
| Expression | Meaning |
| --- | --- |
| yes\|no | Either value |Escape the pipe inside inline code too
In GFM table cells, backticks do not stop the table parser from recognizing a pipe separator. Keep the backslash inside the code span.
| Regex | Result |
| --- | --- |
| `cat\|dog` | Matches cat or dog |Commands and operators need the same treatment
Shell pipelines, TypeScript unions and other code frequently contain pipes. Escape every literal pipe that belongs to the cell rather than the table structure.
| Example | Context |
| --- | --- |
| `cat app.log \| grep ERROR` | Shell pipeline |
| `string \| null` | Type union |Generated Markdown may need another escaping layer
When Markdown source is itself stored in JSON, JavaScript or another string format, that outer language may also consume backslashes. Inspect the final Markdown text rather than assuming the source-code literal contains the intended \| sequence.
const cell = "yes\\|no"; // produces yes\|no in MarkdownFallbacks depend on the renderer
A numeric HTML entity such as | may work where HTML entities are supported, but the portable GFM solution is the documented backslash escape. Test the final destination before standardizing a fallback.
Quick troubleshooting checklist
- Count the intended columns in the header, delimiter and body row.
- Escape only content pipes, not structural separators.
- Keep the escape inside inline code spans.
- Account for JSON or programming-language string escaping.
- Preview the exact generated Markdown in the target renderer.
Try the example
Keep literal pipes inside Markdown cells
Regex, shell and type-union examples use backslash escapes so their pipes do not create extra columns.
| Example | Context |
| --- | --- |
| `cat\|dog` | Regex alternation |
| `cat app.log \| grep ERROR` | Shell pipeline |
| `string \| null` | Type union |Expected result: The imported table has exactly two columns, and every escaped pipe remains visible inside its intended cell.
Test the edge case
Import a table containing escaped pipes
Load a GFM table with regex and shell-style pipe examples and inspect the generated source and preview.