From dc7b8968e678f51ea00e2be3fe8c717d114691a3 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 23 Sep 2026 14:24:43 +0800 Subject: [PATCH] Disable `singleDollarTextMath` in `mdast-util-math` (#20140) --- changelog_unreleased/markdown/20140.md | 13 +++++++++++ src/language-markdown/parse/parse-markdown.js | 2 +- .../math/__snapshots__/format.test.js.snap | 23 ++++++++++++++++++- tests/format/markdown/math/issue-20135.md | 5 ++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 changelog_unreleased/markdown/20140.md create mode 100644 tests/format/markdown/math/issue-20135.md diff --git a/changelog_unreleased/markdown/20140.md b/changelog_unreleased/markdown/20140.md new file mode 100644 index 000000000..7ccb73147 --- /dev/null +++ b/changelog_unreleased/markdown/20140.md @@ -0,0 +1,13 @@ +#### Fix text with `$` been incorrectly parsed as math syntax (#20140 by @fisker) + + +```md + +**Uses $FOO** from `a.sh` and `b.sh`, plus `$BAR` from `c.sh`, before anything else runs here. + + +**Uses $FOO** from `a.sh` and `b.sh`, plus `$BAR`from`c.sh`, before anything else runs here. + + +**Uses $FOO** from `a.sh` and `b.sh`, plus `$BAR` from `c.sh`, before anything else runs here. +``` diff --git a/src/language-markdown/parse/parse-markdown.js b/src/language-markdown/parse/parse-markdown.js index ba7f76a2b..32888ee21 100644 --- a/src/language-markdown/parse/parse-markdown.js +++ b/src/language-markdown/parse/parse-markdown.js @@ -17,7 +17,7 @@ function getMarkdownParseOptions() { return (markdownParseOptions ??= { extensions: [ gfmSyntax({ singleTilde: false }), - mathSyntax(), + mathSyntax({ singleDollarTextMath: false }), wikiLinkSyntax({ // We don't need support alias, use a fake string to bypass // https://github.com/stereobooster/braindb/blob/66d6cf74d0bad43f20924a14e382a432ff81cdfa/packages/micromark-extension-wiki-link/src/syntax.ts#L81 diff --git a/tests/format/markdown/math/__snapshots__/format.test.js.snap b/tests/format/markdown/math/__snapshots__/format.test.js.snap index 291f12842..84fa7c571 100644 --- a/tests/format/markdown/math/__snapshots__/format.test.js.snap +++ b/tests/format/markdown/math/__snapshots__/format.test.js.snap @@ -66,6 +66,27 @@ $$ \\textrm{p-value} = 1 - \\sum_{x \\leq a} H(x | N, r_1, m_1) $$ ================================================================================ `; +exports[`issue-20135.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] + printWidth: 80 (default) | +=====================================input====================================== +**Uses $FOO** from \`a.sh\` and \`b.sh\`, plus \`$BAR\` from \`c.sh\`, before anything else runs here. + +**Sourced-from-$DOTFILES files** - listed in \`.stow-local-ignore\`. They live only inside the repo +and are pulled in by \`.zshrc\` via \`$DOTFILES\` (which is set to \`~/.dotfiles\` in \`.zshrc\`). Key +examples: \`exports.zsh\`, \`aliases.zsh\`, \`dirs.zsh\`, \`completions/\`, \`_plugins/loader.zsh\`. + +=====================================output===================================== +**Uses $FOO** from \`a.sh\` and \`b.sh\`, plus \`$BAR\` from \`c.sh\`, before anything else runs here. + +**Sourced-from-$DOTFILES files** - listed in \`.stow-local-ignore\`. They live only inside the repo +and are pulled in by \`.zshrc\` via \`$DOTFILES\` (which is set to \`~/.dotfiles\` in \`.zshrc\`). Key +examples: \`exports.zsh\`, \`aliases.zsh\`, \`dirs.zsh\`, \`completions/\`, \`_plugins/loader.zsh\`. + +================================================================================ +`; + exports[`math-like.md format 1`] = ` ====================================options===================================== parsers: ["markdown"] @@ -78,7 +99,7 @@ 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... +Paragraph with $14 million. But if more $dollars on the same line... ================================================================================ `; diff --git a/tests/format/markdown/math/issue-20135.md b/tests/format/markdown/math/issue-20135.md new file mode 100644 index 000000000..87b1a94db --- /dev/null +++ b/tests/format/markdown/math/issue-20135.md @@ -0,0 +1,5 @@ +**Uses $FOO** from `a.sh` and `b.sh`, plus `$BAR` from `c.sh`, before anything else runs here. + +**Sourced-from-$DOTFILES files** - listed in `.stow-local-ignore`. They live only inside the repo +and are pulled in by `.zshrc` via `$DOTFILES` (which is set to `~/.dotfiles` in `.zshrc`). Key +examples: `exports.zsh`, `aliases.zsh`, `dirs.zsh`, `completions/`, `_plugins/loader.zsh`.