Remark: Table cell mis-parsing caused by empty `inlineCode`

Created on 17 Jan 2018  ·  2Comments  ·  Source: remarkjs/remark

Subject of the issue

| col1 | col2 | col3 |
|---|--|--|
| long text | `` | text |

Steps to reproduce

astexplorer

Expected behaviour

{
  "type": "tableRow",
  "children": [
    {
      "type": "tableCell",
      "children": [
        {
          "type": "text",
          "value": "long text"
        }
      ]
    },
    {
      "type": "tableCell",
      "children": [
        {
          "type": "inlineCode",
          "value": ""
        }
      ]
    },
    {
      "type": "tableCell",
      "children": [
        {
          "type": "text",
          "value": "text"
        }
      ]
    }
  ]
}

Actual behaviour

{
  "type": "tableRow",
  "children": [
    {
      "type": "tableCell",
      "children": [
        {
          "type": "text",
          "value": "long text"
        }
      ]
    },
    {
      "type": "tableCell",
      "children": [
        {
          "type": "inlineCode",
          "value": ""
        },
        {
          "type": "text",
          "value": " | text"
        }
      ]
    }
  ]
}
remark-parse 🐛 typbug 👶 semvepatch

Most helpful comment

GitHub renders it like this:

| col1 | col2 | col3 |
|---|--|--|
| long text | `` | text |

Which is super weird 🤔

All 2 comments

GitHub renders it like this:

| col1 | col2 | col3 |
|---|--|--|
| long text | `` | text |

Which is super weird 🤔

Uhm, I think I get why GitHub is “weird”. Because there’s no good solution. Your expected behaviour is not going to work. I don’t like how GH does it, but we can change remark’s actual behaviour.

Take this example:

Markdown
| 1 | 2 | 3 |
|-|-|-|
| a | `` | text |
| b | `` | `` |
| c | ` | ` |
| d | `|` | 
| e | `\|` | 
| f | \| | 
Rendered on GitHub

| 1 | 2 | 3 |
|-|-|-|
| a | | text | | b | | `| | c | | | | d ||| | e ||` |
| f | | |

Things of note
  • Inline code in tables is different because you can’t have vertical bars (|) inside inline code, in a table, the vertical bar always creates a new cell (except when escaped with a backslash, such as in row e and f)
  • How do you detect empty inline code? You walk till you can’t walk anymore, and if you don’t find an equal length fence, and the opening fence is an even number of grace accents, it is deemed empty. GitHub does not allow empty inline code in tables.
Now what?

Not really sure! 🤷‍♂️ This issue “Table cell mis-parsing caused by empty inlineCode” is an issue with GFM. Also with remark, because we don’t support it either. And we support it differently. We can match GH but it’s not going to solve this issue 🤔

Was this page helpful?
0 / 5 - 0 ratings