vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Markdown Editor: escaped dollar signs (\$, $) disappear, and two prices in one paragraph render as inline math

Open kylelovespi opened this issue 2 months ago • 3 comments

  • VS Code Version: 1.136.1 (a44adf7f53e00964ab890f9f8758a334f1fc15bc, arm64)
  • OS Version: macOS 26.5.2
  • Does this issue occur when all extensions are disabled?: Yes (reproduced in a window started with code --disable-extensions)

Affects the built-in Markdown Editor (vscode.markdown.editor, the hybrid/WYSIWYG editor). The plain Markdown Preview renders the same file correctly.

Steps to reproduce

  1. Create a .md file with these lines:
1. bare: only the $530 one vs "$1,027 misdirected, not $530" ($497 also)
2. backslash: only the \$530 one vs "\$1,027 misdirected, not \$530" (\$497 also)
3. numeric entity: only the $530 one vs "$1,027 misdirected, not $530" ($497 also)
4. named entity: only the $530 one vs "$1,027 misdirected, not $530" ($497 also)
5. code span: only the `$530` one vs "`$1,027` misdirected, not `$530`" (`$497` also)
  1. Right-click the tab, Open With, Markdown Editor.

Expected

Lines 1-4 show the dollar signs as ordinary text. Per CommonMark, \$, $, and $ are a literal $, and prose with two prices in one paragraph is not math. The Markdown Preview renders all five lines correctly.

Actual

  • Line 1: $530 one vs "$ and $530" ($ are rendered as inline math (KaTeX italics), leaving 1,027 misdirected, not and 497 also) as text.
  • Lines 2, 3, 4: the dollar signs are removed entirely; the line reads only the 530 one vs " 1,027 misdirected, not 530" ( 497 also) with blank space where each $ was.
  • Line 5 (code spans) is the only form that shows the sign.

Notes from the shipped bundle

extensions/markdown-language-features/markdown-editor-out/editor.js uses micromark with micromark-extension-math (singleDollarTextMath defaults to true). That tokenizer has no closing-delimiter adjacency check, unlike the preview's @vscode/markdown-it-katex, which refuses a closer followed by a digit or preceded by whitespace. Running the same lines through micromark + micromark-extension-math directly returns a literal $ for lines 2-4, so the loss of the escaped sign happens in the editor's rendering layer, not the parser. Nothing in dist/extension.js wires markdown.math.enabled to this editor, so there is no setting that turns math off here.

Suggested fixes (any one helps)

  • Honor \$, $, and $ as literal text in the rendered view.
  • Apply the same closing-delimiter adjacency rule the Markdown Preview uses for $...$.
  • Let markdown.math.enabled: false disable math in this editor too.

kylelovespi avatar Sep 07 '26 15:09 kylelovespi

Thanks @kylelovespi for filing this bug! I just independently found this bug as well as I was trying to use the Markdown Editor feature in VS Code. Would love to see this fixed.

cristian-aldea avatar Nov 14 '26 04:11 cristian-aldea

Still reproduces in 1.148.0 (Linux, Remote-SSH window): two prices in one paragraph render as inline math, and \$ disappears. markdown.math.enabled has no effect on this editor.

Workaround until this is fixed:

in extensions/markdown-language-features/markdown-editor-out/editor.js, change the singleDollarTextMath default to false (return x==null&&(x=!0) → return x=!1) and reload the window.

After that only $$…$$ is treated as math. In a Remote-SSH window the copy to patch is the one under ~/.vscode-server/bin/<commit>/ on the remote. The change is lost on every update.

InfectedIsm avatar Nov 25 '26 14:11 InfectedIsm

Fixed in @vscode/[email protected], adopted in #350722.

hediet avatar Dec 01 '26 14:12 hediet