Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting of other languages inside tagged template strings and commented template strings #484

Closed
4 tasks done
karlhorky opened this issue Dec 8, 2024 · 7 comments
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@karlhorky
Copy link

karlhorky commented Dec 8, 2024

Initial checklist

Problem

Using the following VS Code extensions allows for highlighting inside of tagged template strings (eg. css or html or sql tagged template strings) and template strings with a comment before them, see right side of VS Code editor

On the MDX side (left side):

  1. The first CSS code inside of the code block is syntax highlighted
  2. The subsequent CSS code in the tagged template strings are not syntax highlighted

Screenshot 2024-12-08 at 12 11 41

Current solutions

I haven't seen a full solution to this with MDX, no.

I have seen that markdown-tm-language highlights other languages inside of Markdown code blocks (aka code fences), shown in the demo:

Screenshot 2024-12-08 at 12 20 09

But this is not a tagged template string or comment template string, which can be important for features of template strings.

Proposed solutions

Identify template strings within MDX as template strings which the other extensions can add highlighting to.

Alternatives considered

  1. Maybe this actually needs to be added to each of these other extensions? (to enable this syntax highlighting for MDX files?)
  2. At first, I thought this may need to be a part of markdown-tm-language, but then, thinking through it more, it doesn't seem to fit, because this is only a TextMate grammar.
@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Dec 8, 2024
@karlhorky karlhorky changed the title Syntax highlighting with tagged template strings and commented template strings Syntax highlighting of other languages inside tagged template strings and commented template strings Dec 8, 2024
@remcohaszing
Copy link
Member

We can’t support all possible embedded languages inside MDX files. It’s out of scope of this project. Neither can the builtin TypeScript syntax, that’s why you have those third party extensions.

We have documented how extensions can do this specifically for code blocks in packages/vscode-mdx. Some practical examples:

@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024

This comment has been minimized.

@remcohaszing remcohaszing added 👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Dec 9, 2024

This comment was marked as resolved.

@karlhorky
Copy link
Author

We have documented how extensions can do this specifically for code blocks

Yeah, if you mean the 3-backtick Markdown-style code blocks (aka code fences), that's not what I'm trying to get at with this issue (code blocks are mentioned under "Current Solutions")

It's about tagged template literals in JSX expressions:

css`
  em { color: red }
`

We can’t support all possible embedded languages inside MDX files. It’s out of scope of this project. Neither can the builtin TypeScript syntax, that’s why you have those third party extensions.

I'm not proposing that MDX Analyzer perform the syntax highlighting - I'm proposing that MDX Analyzer should expose / identify template strings in such a way so that third party extensions also work in MDX documents:

Proposed solutions

Identify template strings within MDX as template strings which the other extensions can add highlighting to.

But maybe I'm wrong that MDX Analyzer has anything to do here - maybe this is on the third party extensions, that they support highlighting in JSX expressions inside of MDX documents?

They would need to parse the MDX I guess...?

Alternatives considered

  1. Maybe this actually needs to be added to each of these other extensions? (to enable this syntax highlighting for MDX files?)

@remcohaszing
Copy link
Member

Syntax highlighting is done using TextMate grammers. The other extensions need to inject the right grammar into the right scope. There’s no difference between say injecting Mermaid or CSS syntax into markdown code blocks, JavaScript template literals, or block comments. There’s no parsing involved and no work to be done on MDX analyzer.

@karlhorky
Copy link
Author

Ok got it, so if I'm understanding correctly, it would need to be a grammar update on these other extensions to add template string highlighting support within MDX.

@karlhorky
Copy link
Author

Created a first issue over here, let's see if the other extensions are open to implementing:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants