pulldown-cmark: Problems with escaping pipes in tables

There doesn’t seem to be a way to escape pipes inside a backtick string inside a table. Example:

| My Table |
|----------|
| `Foo \| Bar` |

Returns a code event with the literal backslash still in it: Code(Borrowed("Foo \\| Bar")).

However, if you don’t include the backslash, it breaks the table (and indeed, that is what GitHub renders here):

image

This is complicated since inside a backtick string per the commonmark spec, “All backslashes are treated literally”. The GHFM spec has an escape hatch here where they specify “Include a pipe in a cell’s content by escaping it, including inside other inline spans”. So there is a little conflict there, but I think if pulldown-cmark wants to follow GHFM tables, it should probably handle escapes the same way.

A workaround for now is to use HTML, such as <code>Foo \| Bar </code> or <code>Foo &vert; Bar </code>

EDIT: Original issue below, the rest of the issues below have been fixed.


I’m running into some issues with escaping pipes which makes it difficult to use them in tables.

Escaping only works at the beginning inside backticks

Given the text `\|` I get the expected event Code(Borrowed("|")).

Given the text `foo \|` I get Code(Borrowed("foo \\|")), notice the unexpected backslash in the output. Escaping a pipe only works if it is the very first thing inside backticks. I would expect it to work anywhere inside backticks.

Escaping inside code block does not work

Given the text <code>\|</code> results in exactly the same output (that is, with the backslash). I would expect the backslash to be removed (and is how GitHub interprets it). This is an issue because if you try to use <code>|</code> inside a table, the pipe is interpreted as a column separator. Adding the backslash prevents that, but results in an unwanted backslash in the output.

For now I think I’ll be able to work around this using &vert;.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@camelid Yes. When tables are enabled, the escaping behavior of pipes inside a table cell does not match GitHub’s behavior. All the other situations seem to be fixed.

I have a fix for the non table stuff!On Jul 11, 2019 08:51, Raph Levien notifications@github.com wrote:I’d like to get a fix for this in soon, but maybe we can split the table stuff out into a separate bug, as I’m not sure there’s a consensus on how to handle it.

—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.