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

fix(markdown): do not trim content in inline-math #5485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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