-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Highlight HTML, CSS, Markdown, GraphQL in JS tagged template literals #1930
Comments
Great suggestion! There is one thing I want to add to the list of non-tagged literals: div.innerHTML = `
<em>Foo</em>
`; (Even GitHub highlights this)
I really don't like the idea of Prism specific syntax for the sole purpose of highlighting. |
Cool, sounds great :)
Prettier formats HTML and GraphQL with these comments. But yeah, not such a big deal. |
It seems like #1714 has part of (all of) the |
While it's true that these tagged literals are quite common for frameworks, they are not part of the JS language spec and therefore should be an optional opt-in feature IMO. My preferred solution here is a new language which handles all languages embedded in JS templates. I'm thinking of something along the lines of JS Templates. This makes the whole thing opt-in and keeps main JS lang light. |
is it not suport highlight |
@lunalusy I can't reproduce your issue. What is the exact code that is highlighted incorrectly? |
@RunDevelopment I just realized I didn't have SQL in the list above - just added it: const users = await sql`
SELECT * FROM users WHERE id = ${id}
`; What do you think about also supporting SQL template literals? I tried enabling it with |
By the way, I couldn't figure out how to use this on the Test Drive, as I was trying to test whether Prism already had support for SQL tagged template literals. I tried the following code, which I believe should work... 🤔 const a = css`a { color: #25F; }` I tried it by enabling the languages in this order (not sure this is correct):
|
No, SQL isn't supported yet. I'll add it. This load order is correct and works for me. Did you maybe not start with CSS when the page was loaded? |
Ah maybe, yep! I may have actually started with JS, and then done the list above. For some reason, I thought that if I continued to load, then they would bootstrap themselves correctly. But I guess reloading the page before step 1 with CSS was the right trick here. |
Amazing, thanks! |
Syntax highlighting for tagged template literals would be very helpful, especially in languages close to JS such as ReScript: Example: Compare with: https://relay.dev/docs/tutorial/fragments-1/#step-1--define-a-fragment |
Motivation
Prism doesn't highlight supported languages when they are in a tagged template literal with common tags.
Description
Support for common tagged template literals such as:
To allow this highlighting behavior without adding a tag call, one option is to also support comments in the place of tags:
There are also other non-template literal syntaxes which are potentially desired:
Prettier has some AST tests for these things which could probably be repurposed here (or at least, could inspire a solution):
HTML tagged template literals:
CSS tagged template literals:
Markdown tagged template literals:
GraphQL tagged template literals:
Edit: It seems like #1714 has part of (all of) the styled-components implementations, and maybe this could be repurposed to achieve all the other languages.
The text was updated successfully, but these errors were encountered: