Skip to content

Problems with escaping pipes in tables #356

Description

@ehuss

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;.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions