Skip to content

Commit

Permalink
Highlight JS tagged template literals (#1931)
Browse files Browse the repository at this point in the history
This adds support for highlighting embedded languages in JavaScript tagged template literals.
  • Loading branch information
RunDevelopment committed Jul 21, 2019
1 parent 452d5c7 commit c884428
Show file tree
Hide file tree
Showing 21 changed files with 901 additions and 41 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,18 @@
],
"owner": "RunDevelopment"
},
"js-templates": {
"title": "JS Templates",
"require": "javascript",
"peerDependencies": [
"css",
"css-extras",
"graphql",
"markdown",
"markup"
],
"owner": "RunDevelopment"
},
"json": {
"title": "JSON",
"owner": "CupOfTea696"
Expand Down Expand Up @@ -750,7 +762,8 @@
"require": ["markup", "javascript"],
"peerDependencies": [
"jsdoc",
"js-extras"
"js-extras",
"js-templates"
],
"owner": "vkbansal"
},
Expand Down Expand Up @@ -892,6 +905,7 @@
"typescript": {
"title": "TypeScript",
"require": "javascript",
"peerDependencies": "js-templates",
"alias": "ts",
"owner": "vkbansal"
},
Expand Down
9 changes: 7 additions & 2 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ Prism.languages.insertBefore('javascript', 'keyword', {

Prism.languages.insertBefore('javascript', 'string', {
'template-string': {
pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|[^\\`])*`/,
pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
greedy: true,
inside: {
'template-punctuation': {
pattern: /^`|`$/,
alias: 'string'
},
'interpolation': {
pattern: /\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
lookbehind: true,
inside: {
'interpolation-punctuation': {
pattern: /^\${|}$/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c884428

Please sign in to comment.