diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index f37cb99b094b..a6b43ddbb38e 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -409,13 +409,12 @@ function genericPrint(path, options, print) { "$$" ]); case "inlineMath": { - // $$math$$ can be block math in some variants - // see https://github.com/Rokt33r/remark-math#double-dollars-in-inline - const style = - options.originalText[node.position.start.offset + 1] === "$" - ? "$$" - : "$"; - return concat([style, node.value, style]); + // remark-math trims content but we don't want to remove whitespaces + // since it's very possible that it's recognized as math accidentally + return options.originalText.slice( + options.locStart(node), + options.locEnd(node) + ); } case "tableRow": // handled in "table" diff --git a/tests/markdown_math/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_math/__snapshots__/jsfmt.spec.js.snap index a70ef75ce3cb..aa24f4331aca 100644 --- a/tests/markdown_math/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_math/__snapshots__/jsfmt.spec.js.snap @@ -28,6 +28,13 @@ $$ `; +exports[`math-like.md - markdown-verify 1`] = ` +$10 - $20 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +$10 - $20 + +`; + exports[`remark-math.md - markdown-verify 1`] = ` diff --git a/tests/markdown_math/math-like.md b/tests/markdown_math/math-like.md new file mode 100644 index 000000000000..832901386322 --- /dev/null +++ b/tests/markdown_math/math-like.md @@ -0,0 +1 @@ +$10 - $20