Skip to content

Commit

Permalink
fix(markdown): do not trim content in inline-math (#5485)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Nov 15, 2018
1 parent e588533 commit 043a937
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/language-markdown/printer-markdown.js
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions tests/markdown_math/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -28,6 +28,13 @@ $$
`;

exports[`math-like.md - markdown-verify 1`] = `
$10 - $20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$10 - $20
`;

exports[`remark-math.md - markdown-verify 1`] = `
<!-- tests from https://github.com/Rokt33r/remark-math/blob/9e13e49/specs/remark-math.spec.js -->
Expand Down
1 change: 1 addition & 0 deletions tests/markdown_math/math-like.md
@@ -0,0 +1 @@
$10 - $20

0 comments on commit 043a937

Please sign in to comment.