Markdown syntax highlighting: line-leading `$` starts a math block and affects the rest of the document
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Description
In a Markdown document, a line beginning with a single dollar sign is interpreted as the start of a multiline math block.
If the line does not contain a closing `$`, the remaining document is highlighted incorrectly. Headings and other Markdown syntax after that line lose their normal highlighting.
This commonly affects Markdown containing shell prompts, commands, or environment variables.
## Steps to reproduce
1. Launch a fresh VS Code window with all extensions disabled:
```sh
code --disable-extensions --new-window vscode-markdown-dollar-repro.md
```
2. Open a Markdown file containing:
```markdown
# Before
$ echo "hello"
# After
**This should be bold**
```
3. Compare the highlighting before and after the line beginning with `$`.
## Actual behaviour
The leading `$` starts a multiline math scope. The remainder of the document is highlighted as math until another dollar sign is encountered, so `# After` and the bold text are no longer highlighted as Markdown.
## Expected behavior
A line-leading `$` that does not form a closed math expression should remain ordinary Markdown text and must not affect tokenisation of subsequent lines.
## Environment
- VS Code: 1.133.0
- Commit: `a5b500951314efd502d07465bd138dfbd714a960`
- Architecture: arm64
- OS: macOS 26.5.1 (25F80)
- Extensions disabled: Yes
- VS Code Insiders: Not tested
## Additional context
This appears related to:
- https://github.com/microsoft/vscode/issues/136535
- https://github.com/microsoft/vscode-markdown-tm-grammar/issues/148
Issue #136535 fixed the case where `$` is followed by a digit, such as `$12.45`. The current single-dollar block rule still treats lines such as `$ command`, `$PATH`, or `$foo` as the beginning of a multiline math block:
https://github.com/microsoft/vscode/blob/main/extensions/markdown-math/syntaxes/md-math-block.tmLanguage.json#L48-L50
The relevant rule is:
```regex
(?<=^\s*)(\$)(?![^$]*\$|\d)
```
Contributor guide
Assessment
This issue has not been assessed yet.