How to escape a pipe char in a code statement in a markdown table?

前端 未结 3 1794
天命终不由人
天命终不由人 2020-11-30 21:26

On GitHub I want to build a table containing pieces of code in Markdown. It works fine except when I put a pipe char (i.e. | ) between the backtick (i.e. ` ) chars.

相关标签:
3条回答
  • 2020-11-30 22:16

    As of mid-2017, the pipe may simply be escaped with a backslash, like so: \|

    This works both inside and outside of backticks.

    The HTML code may now be used again, too, but only outside of backticks.

    Previous answer:

    As of March 2017, the accepted answer stopped working because GitHub changed their markdown parser. Using another unicode symbol that resembles a pipe seems to be the only option right now, e.g.:

    ǀ (U+01C0, Latin letter dental click)

    ∣ (U+2223, Symbol divides)

    ⎮ (U+23AE, Integral Extension)

    0 讨论(0)
  • 2020-11-30 22:19

    You can escape the | in a table in GFM with a \ like so:

          a     |  r  
    ------------|-----
     `a += x;`  |  r1
     `a \|= y;` |  r2
    

    See https://github.github.com/gfm/#example-191 or https://github.com/dotnet/csharplang/pull/743 for an example.

    0 讨论(0)
  • 2020-11-30 22:21

    As of March 2017 using escaped pipes is much easier: \| See other answers.

    If you remove the backticks (`), using the | hack works

          a     |  r  
    ------------|-----
     `a += x;`  |  r1
     a |= y;  |  r2
    

    and produces the following output

    enter image description here

    Alternatively, you can replace the backticks (`) with a <code></code> markup which fixes the issues more nicely by preserving the rendering

          a     |  r  
    ------------|-----
     `a += x;`  |  r1
    <code>a &#124;= y;</code>  |  r2
    

    generating the following output

    enter image description here

    0 讨论(0)
提交回复
热议问题