microsoft / microsoft/vscode

Markdown: escaped `\$` opens an inline math span and hides highlighting until the next `$`

Open
#335,663 0 comments 0 reactions 1 assignee Claimed by @hediet View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Does this issue occur when all extensions are disabled?: Yes

- VS Code Version: 1.137.0 (645f29cc3176500b4b5762ba887cf2a7f0ffdf2c, x64)
- OS Version: Ubuntu 22.04.5 LTS

This is about editor syntax highlighting in a plain Markdown file, not the preview. The grammar in `extensions/markdown-math/syntaxes/md-math-inline.tmLanguage.json` is the same on `main`.

Steps to Reproduce:

1. Open a new `.md` file and paste this paragraph:
```
Let’s consider a DvP of X vs \$ where the two assets are provided by different `admin` parties. The allocations between the two tokens will always be settled independently as the `admin` party of X does not validate the \$ settlement and vice versa.
```
2. Look at the two `` `admin` `` code spans.

**Expected:** both `` `admin` `` spans are highlighted as inline code. `\$` is an escaped, literal dollar sign per CommonMark and must not open a math span.

**Actual:** neither `` `admin` `` is highlighted, i.e. both are in plain text. Everything from the first `\$` to the next `\$` is tokenized as `markup.math.inline.markdown`.

**Workaround:** wrap the first `\$` in backticks.

**Cause:** the `math_inline_single` rule uses

```
(?<=\s|\W|^)(?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.