Skip to content

Markdown syntax highlighting in code blocks breaks in VS Code when template expressions are used #1855

Answered by mootari
jschuur asked this question in Q&A
Discussion options

You must be logged in to vote

It's known (see e.g. #263), but currently not fixable. The gist is that a line starting with $ is detected as the start of a LaTeX expression which has to be closed by a second $.

Here are a couple of workarounds:

  • Start the line with a white space: ${foo}
  • Mark the section as HTML by wrapping it in a tag: <div>${foo}</div>
  • Add the closing delimiter in an HTML comment: ${foo}<!--$-->
  • Add the closing delimiter in a JS comment: ${foo /*$*/}
  • Use a $ prefixed variable name: ${$foo}
  • Define a dummy variable const $ = ... somewhere, then use it in a comma expression: ${$, foo}

Properly supporting interpolations would require implementing either a custom TextMate grammar (likely on top of VS Cod…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@mootari
Comment options

mootari Dec 1, 2024
Collaborator

@jschuur
Comment options

Answer selected by Fil
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants