Document conversion guide
How to Escape a Pipe in a Markdown Table
Keep a literal pipe inside a Markdown table cell without creating extra columns. See examples for plain text, inline code, and Excel conversion.
To escape a pipe in a Markdown table, put a backslash immediately before the pipe: \|. In GitHub Flavored Markdown, this keeps the character inside its cell instead of treating it as a column boundary. Apply the same escape when the pipe appears inside an inline code span in a table.
This is easy to miss because the character has two jobs. In the table structure, | separates cells. Inside a command, an option label, or a regular expression, it can be meaningful text. A table renderer needs enough information to distinguish those uses before it can lay out the columns correctly.
Start with a small working example
Here is a two-column table with a literal pipe in the first data cell:
| Choice | Meaning |
| --------- | ----------------- |
| Yes \| No | Select one answer |
The intended first value is “Yes | No.” Without the backslash, the parser can interpret the row as three cells: “Yes,” “No,” and “Select one answer.” Depending on the renderer, the extra value may be truncated, pushed into a different column, or rejected.
The surrounding spaces do not protect a pipe. Neither does putting the value in ordinary quotation marks. A value such as "Yes | No" still contains a structural pipe in Markdown table syntax. Spreadsheet CSV quoting and Markdown table escaping are different rules; importing habits from one format into the other is a common source of errors.
Escape pipes inside inline code too
Inline code normally uses backticks to show literal text. However, in a GitHub Markdown table, you should still escape a pipe within that code span:
| Command | Purpose |
| ----------------------- | ------------------------------- |
| `printf hello \| wc -c` | Count the output characters |
| `left \| right` | Show a literal operator example |
The GitHub Flavored Markdown table specification explicitly covers escaped pipes within inline constructs, including code spans. That table-specific behavior is why an example can work in a normal paragraph but break when moved into a cell.
When a command becomes long or contains several shell operators, consider taking it out of the table. Put a short description in the cell and show the complete command in a fenced code block beneath the table. Readers can then copy the command more easily, and the table stays usable on phones.
Do not add the table escape to the actual command you intend someone to run. Its purpose is to encode the displayed character in the Markdown source. Review the rendered result, then verify that copying the rendered code produces the intended command for your destination environment.
Be careful with HTML entities and repeated escaping
An HTML entity such as | can represent a pipe in some rendered contexts. It is not an interchangeable fix everywhere. Inside a code span, an entity may remain visible as the characters &, #, 1, 2, 4, and ;. A downstream spreadsheet converter may also preserve that literal text instead of decoding it.
For a GitHub table, use the documented backslash escape first. Reach for an entity only when you have tested the exact destination and know why that representation is required.
Also distinguish the Markdown file from the programming language that creates it. A JavaScript string, a JSON value, and the resulting Markdown file can have different escaping layers. For example, a generator may need extra backslashes in its own source so that the final Markdown contains a single backslash before the pipe. Inspect the generated .md file rather than counting backslashes only in the generator’s source code.
Check all rows when a column appears to be missing
Begin with the header and separator row. They should describe the same number of columns. Then look for the first data row that shifts values into the wrong headings.
Reduce the problem to that row plus the header. Replace a complex cell temporarily with a short value such as “sample.” If the row starts working, restore the original value a few characters at a time. Literal pipes are a likely cause, but missing separators, an unclosed code span, or an accidental physical newline can also change how the source is interpreted.
Use the Markdown to HTML converter to inspect a small example quickly, and then check the same source in the actual destination. GitHub-style tables are an extension to Markdown, so every renderer should not be assumed to implement identical edge cases.
Keep pipes intact when moving tables into Excel
The Markdown table to Excel converter on this site recognizes escaped pipe characters and checks that each row has the same number of cells as its header. Its preview is useful for confirming that a label containing a pipe remains one cell before you copy TSV or download a workbook.
That converter works with table text values. It does not turn inline code markup into a rich spreadsheet code object, and you should not assume that an HTML entity will be decoded just because a browser preview decodes it. Check the exported value of a representative cell if punctuation is significant.
For the reverse direction, the Excel to Markdown table converter escapes literal pipes when it produces the table source. Avoid running a second blanket “escape every pipe” replacement over that output: doing so would also escape the delimiters that define the table itself.
Before sharing the table, check three things: the column count is stable, each literal pipe appears where expected, and a value copied from the rendered output remains useful in its next application. A correct escape should solve the layout problem without changing the information inside the cell.