Skip to content

Code with pipe character in table is impossible to write correctly #2000

Open
@iFreilicht

Description

@iFreilicht

Problem

This was discovered in NixOS/nix#7770

We have a table with all operators, but || doesn't get rendered correctly:

image

I thought that maybe removing the \ from the markdown would solve this, but no. Comparing a few types of spans:

| code | bold   | ital |
| ---- | ------ | ---- |
|  `|` |  __|__ |  *|* |
| `\|` | __\|__ | *\|* |

Screenshot 2023-01-28 at 20 06 06

The documentation claims that tables are implemented according to the GFM tables extension.

However, this is not the case. From the GFM spec, Example 200:

Include a pipe in a cell’s content by escaping it, including inside other inline spans:

| f\|oo  |
| ------ |
| b `\|` az |
| b **\|** im |

Steps

  1. Create a new mdbook
  2. Paste this code into chapter_1.md:
    | code | bold   | ital |
    | ---- | ------ | ---- |
    |  `|` |  __|__ |  *|* |
    | `\|` | __\|__ | *\|* |
  3. Serve or build the mdbook and observe that either way of putting a pipe symbol inside a code span inside a table doesn't work:
    Screenshot 2023-01-28 at 20 06 06

Possible Solution(s)

It seems mdbook treats the code span as a self-contained unit, so \| does not have special meaning inside the table as it should.

While IMO it would be more intuitive to just have the non-escaped pipe symbol work inside code spans, adhering to the GFM spec would be best in terms of compatibility, so that's what I'd suggest.

Notes

In the end, this minimal markdown

| | |
| - | - |
| `\|` | |

should produce this HTML

<table>
  <thead>
    <tr>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="hljs">|</code></td>
      <td></td>
    </tr>
  </tbody>
</table>

While right now it produces this:

<table>
  <thead>
    <tr>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="hljs">\|</code></td>
      <td></td>
    </tr>
  </tbody>
</table>

Version

mdbook v0.4.25

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MarkdownArea: Issues with markdownC-bugCategory: A bug, incorrect or unintended behaviorS-Blocked-UpstreamStatus: Blocked Upstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions