-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Problem
You have a table that you want to look like this
Regex | Matches |
foo-(1|[3-5])|bar-([39]|39) | foo-1 , bar-39 |
It has some code with pipes in it.
Attempt 1
Your initial solution is just to put the code in the table
| Regex | Matches |
|-----------------------------|-----------------|
|`foo-(1|[3-5])|bar-([39]|39)`|`foo-1`, `bar-39`|
which actually renders as:
Regex | Matches | |||
`foo-(1 | [3-5]) | bar-([39] | 39)` | foo-1 , bar-39 |
because every pipe gets interpreted as a table column.
Attempt 2
The next logical step is to add an escape \
before the |
| Regex | Matches |
|-----------------------------|-----------------|
|`foo-(1\|[3-5])\|bar-([39]\|39)`|`foo-1`, `bar-39`|
Which escapes the |
, but also magically renders your escape \
!
Regex | Matches |
foo-(1\|[3-5])\|bar-([39]\|39) | foo-1 , bar-39 |
This prevents the pipe from being interpreted as a part of the table, but prints the backslash for some reason! This makes it seem like that with pure markdown there is no way to escape the pipe without printing the escape character.
Using HTML
You decide to put inline HTML and replace the backtick with a <code>
tag (sans escape backslashes on the pipe)
| Regex | Matches |
|-----------------------------|-----------------|
|<code>foo-(1|[3-5])|bar-([39]|39)</code>|`foo-1`, `bar-39`|
which renders as:
Regex | Matches | |||
foo-(1 | [3-5]) | bar-([39] | 39) | foo-1 , bar-39 |
This doesn't print the backticks like in the first attempt, and actually shades the first cell as being code. The problem being that we now have pipes making new columns again!
This is the only example so far that works as we would've expected for a parser that doesn't search for the closing tag.
<code>
tag with escape backslash
Using HTML was an improvement, so what if we try out the escape backslashes again?
| Regex | Matches |
|-----------------------------|-----------------|
|<code>foo-(1\|[3-5])\|bar-([39]\|39)</code>|`foo-1`, `bar-39`|
Regex | Matches |
foo-(1\|[3-5])\|bar-([39]\|39) | foo-1 , bar-39 |
Success! Using <code>
tags in conjunction with escape backslashes produces the desired result.
Rendering without inline code
To constrast this with how markdown renders outside of code tags, using an escape backslash works exactly as expected:
| Regex | Matches |
|-----------------------------|-----------------|
|foo-(1\|[3-5])\|bar-([39]\|39)|`foo-1`, `bar-39`|
Regex | Matches |
foo-(1\|[3-5])\|bar-([39]\|39) | foo-1 , bar-39 |
My guess for this is that when a backtick is detected in a table, the table mode searching for unescaped pipes doesn't switch off for unescaped backslashes, leading to the results above.
Expected Results:
You would expect that when you insert a code backtick that everything between the ` `
isn't affected by what context it is in (in this case a table). This is desirable because it is frustrating to have to be aware that what characters you have to escape depends on what kind of structure you already have.
If this is not realizable/goes against the current standard then at the very least I think that using the escape backslash before a pipe should not render.
P.S. attached is a markdown file that contains the examples in this issue (saved as a .txt
because github wouldn't let me up load a markdown file)
chapter_1.txt
P.P.S. It was very difficult to correctly render incorrectly rendering markdown using a differently flavoured markdown |  ̄ヘ ̄|