markdown-to-jsx icon indicating copy to clipboard operation
markdown-to-jsx copied to clipboard

Fenced code blocks are parsed as inline code if backticks are not preceded by two newlines

Open scottopherson opened this issue 1 year ago • 1 comments

Fenced code blocks are parsed as inline code if backticks are not preceded by two newlines.

Example input:

const input = "Run the following commands and verify no results are returned:\n```\n# group\ngrep ^shadow:[^:]*:[^:]*:[^:]+ /etc/group\n# passwd\nawk -F: '($4 == \"<shadow-gid>\") { print }' /etc/passwd\n```"
Run the following commands and verify no results are returned:
```
# group
grep ^shadow:[^:]*:[^:]*:[^:]+ /etc/group
# passwd
awk -F: '($4 == "<shadow-gid>") { print }' /etc/passwd
```

Rendered output:

To get the expected output, an additional newline is needed before the triple backticks:

const input = "Run the following commands and verify no results are returned:\n\n```\n# group\ngrep ^shadow:[^:]*:[^:]*:[^:]+ /etc/group\n# passwd\nawk -F: '($4 == \"<shadow-gid>\") { print }' /etc/passwd\n```"
Run the following commands and verify no results are returned:

```
# group
grep ^shadow:[^:]*:[^:]*:[^:]+ /etc/group
# passwd
awk -F: '($4 == "<shadow-gid>") { print }' /etc/passwd
```

Rendered output:

This behavior is unexpected since Github's markdown compiler seems to only require one newline before the triple backticks. Though they do recommend blank lines before and after code blocks for readability purposes.

scottopherson avatar Sep 06 '23 00:09 scottopherson

Actually I think this may have been previously reported: https://github.com/probablyup/markdown-to-jsx/issues/267

scottopherson avatar Sep 06 '23 00:09 scottopherson