Highlight HTML, CSS, Markdown, GraphQL in JS tagged template literals
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13k
- Forks
- 1.4k
- Avg merge
- 15h 36m
- Merged PRs (30d)
- 3
Description
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:
// HTML
html`...`
// CSS
css`...`
// React Components CSS
styled.foo``
Component.extend``
styled.foo.attr({})``
Component.extend.attr({)``
styled(Component).attr({})``
css.global``
css.resolve``
// Markdown
md`...`
markdown`...`
// GraphQL
gql`...`
graphql`...`
graphql.experimental`...`
// SQL
sql`SELECT * FROM users WHERE id = ${id}`
To allow this highlighting behavior without adding a tag call, one option is to also support comments in the place of tags:
/* HTML */`...`
/* CSS */`...`
There are also other non-template literal syntaxes which are potentially desired:
// Angular Components HTML + CSS
@Component({
template: `<div>...</div>`,
styles: [`h1 { color: blue; }`]
})
// styled-jsx CSS
<style jsx>{`div{color:red}`}</style>
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:
- isCss (overall test for all types of CSS tagged template literals: normal CSS, Angular, React Components)
- isStyledJSX
- isStyledComponent
- isCssProp
- isAngularComponentStyles
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing Prism's existing tagged-template and language-embedding implementation, using the listed Prettier AST helpers as references for HTML, CSS, Markdown, GraphQL, and styled-component cases. Add coverage for the tag and comment forms described in the issue, and verify that each embedded language is highlighted without breaking JavaScript interpolation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, graphql, html, javascript, markdown, sql
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100