PrismJS / PrismJS/prism

Highlight HTML, CSS, Markdown, GraphQL in JS tagged template literals

Open
#1,930 14 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement language-definitions
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.

Screen Shot 2019-06-07 at 11 25 17

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:

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.