Update remark-math to v3 (#7938)
* bump remark-math to 3.0.1 * escape $ only it was escaped in the input * remove unsupported syntax from tests remark-math@3 doesn't support text after the closing fence ($$). Such $$ aren't parsed as a closing fence anymore. * refactor * add a test Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
This commit is contained in:
1 parent
e56dbba6c7
commit
35a1497024
9 files changed
+53
-33
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Update remark-math to 3.0.1; escape dollar signs only if originally escaped (#7938 by @fisker and @thorn0)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```markdown
|
||||
<!-- Input -->
|
||||
Paragraph with $14 million.
|
||||
|
||||
Paragraph with $14 million. But if more $dollars on the same line...
|
||||
|
||||
<!-- Prettier stable -->
|
||||
Paragraph with \$14 million.
|
||||
|
||||
Paragraph with $14 million. But if more $dollars on the same line...
|
||||
|
||||
<!-- Prettier master -->
|
||||
Paragraph with $14 million.
|
||||
|
||||
Paragraph with $14 million. But if more $dollars on the same line...
|
||||
```
|
||||
+1
-1
@@ -73,7 +73,7 @@
|
||||
"postcss-values-parser": "2.0.1",
|
||||
"regexp-util": "1.2.2",
|
||||
"remark-footnotes": "2.0.0",
|
||||
"remark-math": "1.0.6",
|
||||
"remark-math": "3.0.1",
|
||||
"remark-parse": "8.0.3",
|
||||
"resolve": "1.19.0",
|
||||
"semver": "7.3.2",
|
||||
|
||||
@@ -39,25 +39,21 @@ function transformInlineCode(ast) {
|
||||
}
|
||||
|
||||
function restoreUnescapedCharacter(ast, options) {
|
||||
return mapAst(ast, (node) => {
|
||||
return node.type !== "text"
|
||||
return mapAst(ast, (node) =>
|
||||
node.type !== "text" ||
|
||||
node.value === "*" ||
|
||||
node.value === "_" || // handle these cases in printer
|
||||
!isSingleCharRegex.test(node.value) ||
|
||||
node.position.end.offset - node.position.start.offset === node.value.length
|
||||
? node
|
||||
: {
|
||||
...node,
|
||||
value:
|
||||
node.value !== "*" &&
|
||||
node.value !== "_" &&
|
||||
node.value !== "$" && // handle these cases in printer
|
||||
isSingleCharRegex.test(node.value) &&
|
||||
node.position.end.offset - node.position.start.offset !==
|
||||
node.value.length
|
||||
? options.originalText.slice(
|
||||
node.position.start.offset,
|
||||
node.position.end.offset
|
||||
)
|
||||
: node.value,
|
||||
};
|
||||
});
|
||||
value: options.originalText.slice(
|
||||
node.position.start.offset,
|
||||
node.position.end.offset
|
||||
),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function mergeContinuousImportExport(ast) {
|
||||
|
||||
@@ -94,7 +94,7 @@ function genericPrint(path, options, print) {
|
||||
return printChildren(path, options, print);
|
||||
case "word": {
|
||||
let escapedValue = node.value
|
||||
.replace(/[$*]/g, "\\$&") // escape all `*` and `$` (math)
|
||||
.replace(/\*/g, "\\$&") // escape all `*`
|
||||
.replace(
|
||||
new RegExp(
|
||||
[
|
||||
|
||||
@@ -15,11 +15,11 @@ $
|
||||
\\\\\\$
|
||||
|
||||
=====================================output=====================================
|
||||
\\$
|
||||
$
|
||||
|
||||
\\$
|
||||
|
||||
\\\\\\$
|
||||
\\\\$
|
||||
|
||||
\\\\\\$
|
||||
|
||||
@@ -50,9 +50,13 @@ printWidth: 80
|
||||
=====================================input======================================
|
||||
$10 - $20
|
||||
|
||||
Paragraph with $14 million. But if more $dollars on the same line...
|
||||
|
||||
=====================================output=====================================
|
||||
$10 - $20
|
||||
|
||||
Paragraph with $14 million. But if more $dollars on the same line...
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -136,7 +140,7 @@ $$
|
||||
|
||||
$$ must
|
||||
\\alpha
|
||||
$$ be ignored
|
||||
$$
|
||||
|
||||
---
|
||||
|
||||
@@ -156,7 +160,7 @@ $$
|
||||
|
||||
---
|
||||
|
||||
\\$\\alpha\\$
|
||||
$\\alpha\\$
|
||||
|
||||
---
|
||||
|
||||
@@ -168,11 +172,11 @@ $$
|
||||
|
||||
---
|
||||
|
||||
\`$\`\\alpha\\$
|
||||
\`$\`\\alpha$
|
||||
|
||||
---
|
||||
|
||||
\\$\\alpha\`$\` foo
|
||||
$\\alpha\`$\` foo
|
||||
|
||||
---
|
||||
|
||||
@@ -223,6 +227,7 @@ $$
|
||||
---
|
||||
|
||||
$$
|
||||
must
|
||||
\\alpha
|
||||
$$
|
||||
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
$10 - $20
|
||||
|
||||
Paragraph with $14 million. But if more $dollars on the same line...
|
||||
@@ -72,7 +72,7 @@ $$
|
||||
|
||||
$$ must
|
||||
\alpha
|
||||
$$ be ignored
|
||||
$$
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -10750,7 +10750,7 @@ proseWrap: "always"
|
||||
hello $.;'there
|
||||
|
||||
=====================================output=====================================
|
||||
hello \\$.;'there
|
||||
hello $.;'there
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -6202,12 +6202,10 @@ remark-footnotes@2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/remark-footnotes/-/remark-footnotes-2.0.0.tgz#9001c4c2ffebba55695d2dd80ffb8b82f7e6303f"
|
||||
integrity sha512-3Clt8ZMH75Ayjp9q4CorNeyjwIxHFcTkaektplKGl2A1jNGEUey8cKL0ZC5vJwfcD5GFGsNLImLG/NGzWIzoMQ==
|
||||
|
||||
remark-math@1.0.6:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-1.0.6.tgz#49eb3dd15d298734c9ae21673115389793af4d1b"
|
||||
integrity sha512-I43wU/QOQpXvVFXKjA4FHp5xptK65+5F6yolm8+69/JV0EqSOB64wURUZ3JK50JtnTL8FvwLiH2PZ+fvsBxviA==
|
||||
dependencies:
|
||||
trim-trailing-lines "^1.1.0"
|
||||
remark-math@3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-3.0.1.tgz#85a02a15b15cad34b89a27244d4887b3a95185bb"
|
||||
integrity sha512-epT77R/HK0x7NqrWHdSV75uNLwn8g9qTyMqCRCDujL0vj/6T6+yhdrR7mjELWtkse+Fw02kijAaBuVcHBor1+Q==
|
||||
|
||||
remark-parse@8.0.3:
|
||||
version "8.0.3"
|
||||
@@ -7083,7 +7081,7 @@ tr46@^2.0.2:
|
||||
dependencies:
|
||||
punycode "^2.1.1"
|
||||
|
||||
trim-trailing-lines@^1.0.0, trim-trailing-lines@^1.1.0:
|
||||
trim-trailing-lines@^1.0.0:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/trim-trailing-lines/-/trim-trailing-lines-1.1.3.tgz#7f0739881ff76657b7776e10874128004b625a94"
|
||||
integrity sha512-4ku0mmjXifQcTVfYDfR5lpgV7zVqPg6zV9rdZmwOPqq0+Zq19xDqEgagqVbc4pOOShbncuAOIs59R3+3gcF3ZA==
|
||||
|
||||
Reference in new issue
Block a user