如何在降价表中的代码语句中转义管道字符?

如何在降价表中的代码语句中转义管道字符?

问题描述:

在 GitHub 上,我想构建一个包含 Markdown 代码片段的表格.它工作正常,除非我在反引号(即`)字符之间放了一个管道字符(即 | ).

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.

这是我想要的:

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

问题是第二行代码语句中的竖线被解释为列分隔符.然后表格渲染看起来非常难看.我怎么能避免这种情况?

The problem is that the vertical bar in the code statement of the second line is interpreted as a column delimiter. Then the table rendering looks pretty ugly. How could I avoid that?

请注意,我已经尝试使用 | HTML 代码,但它会生成 a |= y;.

Note that I already tried to use the | HTML code, but it produces a |= y;.

截至 2017 年 3 月,使用转义管道要容易得多:| 查看其他答案.

如果您删除反引号 (`),则使用 | hack 作品

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

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

并产生以下输出

或者,您可以使用 <code></code> 标记替换反引号 (`),这样可以通过保留渲染更好地解决问题

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

生成以下输出