quantizor / markdown-to-jsx

🏭 The most lightweight, customizable React markdown component.
https://markdown-to-jsx.quantizor.dev/
MIT License
2.01k stars 174 forks source link

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

Open scottopherson opened 1 year ago

scottopherson commented 1 year ago

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 == "") { 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 == "") { 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 commented 1 year ago

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