Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backslashes appear in output when escaping inline code in a table cell #583

Closed
pjeby opened this issue Dec 19, 2020 · 3 comments
Closed

Backslashes appear in output when escaping inline code in a table cell #583

pjeby opened this issue Dec 19, 2020 · 3 comments

Comments

@pjeby
Copy link

@pjeby pjeby commented Dec 19, 2020

Subject of the issue

When using inline code in a table cell, it's necessary to backslash-escape pipe characters. On Github, the backslashes are removed before parsing the table cell contents, so that they aren't included in the output. Remark doesn't do this, so there is no way to put a pipe character inside inline code in a table cell without at least one spurious backslash being passed through to the output.

(Note that this is not the same issue as #465, which is about what happens if you don't escape the pipe character.)

Your environment

Steps to reproduce

Process this markdown with the remark-gfm extension:

| Ways of Reading Stdout         |     Linux | OS X (bash 3.2) | Windows  |
| ------------------------------ | --------: | --------------: | -------: |
| `[[ ${spork-} ]] \|\| spork ...` |   40433/s |         33840/s |  17667/s |
| Total Performance Improvement  |     34.1x |           24.7x |   271.8x |

Expected behavior

The markdown should be parsed as on Github, dropping the backslashes from the inline code, i.e:

Ways of Reading Stdout Linux OS X (bash 3.2) Windows
[[ ${spork-} ]] || spork ... 40433/s 33840/s 17667/s
Total Performance Improvement 34.1x 24.7x 271.8x

Actual behavior

When parsed with remark 9, neither backslash is removed. When parsed with remark 13, the second and all subsequent backslashed pipe characters in the cell are correctly removed, but the first backslash is passed through unchanged.

@wooorm
Copy link
Member

@wooorm wooorm commented Dec 19, 2020

Thanks PJ for this detailed issue! I read a lot of issues daily where folks remove lots of the issue template and this is great to see!

If I add import html from "remark-html"; and .use(html) to your sandbox, I am seeing two pipes and no backslashes show up. So That does look correct?
However, when serializing to markdown, which is done by default and with your sandbox, only the first pipe is escapes, but further ones aren’t. So I’m guessing this is a bug in how mdast-util-to-markdown serializes pipes in GFM table cells.

Do you think this interpretation of the issue is correct?

@pjeby
Copy link
Author

@pjeby pjeby commented Dec 20, 2020

Well, that's certainly a bug. 😉 Not the one I had in mind, though. This was originally motivated by an issue with Obsidian, which is using remark 8. In remark-parse 9, the same problem exists.

But, as you correctly point out, remark-parse 13 does not have this problem, so that's the version Obsidian needs to upgrade to. It appears that my unfamiliarity with remark made it look like a variation of the problem still existed in 13, but is actually a completely different problem.

So, the tl;dr is that the problem I wanted to report is actually fixed in remark-parse 13, but my test case exposes a completely different issue with mdast-util-to-markdown. 😉

@wooorm
Copy link
Member

@wooorm wooorm commented Jan 2, 2021

Thanks, released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants