2

In a table in Markdown, a pipe character (|) is used to separate columns in a table. However, it's also a pretty common character in code, especially as the bitwise OR operator. When writing inline code blocks in a Markdown table, how should the pipe be escaped, if at all?

There are two candidate methods for writing a pipe in a literal.

This is accepted and rendered correctly by Pandoc and StackOverflow, but not by GitHub:

| My Table!          |
| ------------------ |
| behold, a pipe: `|`|

This is accepted and rendered correctly by GitHub, but not by Pandoc or StackOverflow:

| My Table!           |
| ------------------- |
| behold, a pipe: `\|`|

It seems to be unclear as to whether the pipe needs to be escaped. Does the Markdown specification describe whether the pipe must be escaped?

Inigo
  • 12,186
  • 5
  • 41
  • 70
Clayton Ramsey
  • 123
  • 1
  • 2
  • Does this answer your question? https://stackoverflow.com/questions/17319940/how-to-escape-a-pipe-char-in-a-code-statement-in-a-markdown-table – I0_ol Jan 21 '23 at 17:47
  • I understand how to do it in GitHub - what I'm curious about is what the "correct" implementation is - that is, is GitHub's implementation the right way to do it or are Pandoc and StackOverflow correct? – Clayton Ramsey Jan 21 '23 at 19:25

1 Answers1

2

There is no "correct" way because Markdown has no standard or official specification and its original creator rejected efforts to standardize it or write a spec(1, 2). It turned into an ugly fight. The end result was the balkanization of Markdown.

But the world is converging around CommonMark as standard. Even GitHub Flavored Markdown (GFM) is now a superset of CommonMark.

Pandoc, btw, supports multiple variants of Markdown. You should be able to force it to work the same as GitHub.

StackOverflow is supposed to use CommonMark (one of its founders, Jeff Atwood, was one of the lead people behind CommonMark). But since CommonMark doesn't include table syntax, it looks SO's implementation deviated from GitHub's.

Inigo
  • 12,186
  • 5
  • 41
  • 70
  • The GFM spec does include tables but not everyone follows that (as OP has seen), and even when they do the GFM spec doesn't go into much depth on handling edge cases, so implementations can be all over the place. – Colin O'Dell Jan 22 '23 at 18:52
  • 1
    What's more is that GitHub stopped maintaining the GFM spec. Features like pandoc-like math support and footnotes are not documented in the spec, but have since been included in the GFM implementation. – tarleb Jan 23 '23 at 08:51