Improved markup, CSS, JS tokenization
See original GitHub issueHi! First, thanks of all for this awesome project! It’s affected so many projects around the world. Incredible work!
Motivation
I’m trying to recreate the default VS Code syntax highlighting with Prism.js (via prism-react-renderer) and I’m running into limitations of Prism.js.
Description
I would like to be able to highlight certain tokens that are not granular enough in HTML, CSS and JS.
Would it be something that the Prism.js team is interested in to have more granular tokenization of HTML, CSS and JS? If possible, also with backwards compatibility?
Some first quick examples of things that could be improved across HTML, CSS and JS (compared against VS Code 1.33.1
default dark mode):
HTML: DOCTYPE


HTML: Treating quotes and equals differently than normal punctuation


CSS: URL values


CSS: Arguments in selectors


CSS: Keywords - ex. generic font family names, colors (maybe in CSS-Extra?)




JS: Regex sequences, regex escaping


The code used:
<!DOCTYPE html>
<html lang="en">
<head>
<script>
window.console && console.log('foo');
function initHighlight(block, cls) {
try {
if (cls.search(/\bno\-highlight\b/) != -1)
return process(block, true, 0x0f) + ` class="${cls}"`;
} catch (e) {
/* handle exception */
}
for (var i = 0 / 2; i < classes.length; i++) {
if (checkCondition(classes[i]) === undefined)
console.log('undefined');
}
}
</script>
<title>Prism</title>
<style>
@font-face {
src: url(https://lea.verou.me/logo.otf);
font-family: 'LeaVerou';
}
#features li:nth-child(odd),
footer p {
font: 100% Consolas, 'Andale Mono', monospace;
background-image: linear-gradient(
45deg,
transparent 34%,
white 34%,
white 66%,
transparent 66%
);
text-shadow: 0 1px white;
}
</style>
</head>
</html>
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Standard tokens - Prism.js
Prism identifies tokens in your code, which are in turn styled by CSS to ... Outside of markup languages, it is used to...
Read more >Preprocessing Design System Tokens in CSS-in-JS
Don't throw away your design tokens! Preprocess your CSS-in-JS files to replace references to design tokens with actual values.
Read more >Optimizations in Syntax Highlighting, a Visual Studio Code Story
Optimizations in tokenization and syntax highlighting in the ... Visual Studio Code version 1.9 includes a cool performance improvement that ...
Read more >Standardized Design Tokens and CSS for a consistent ...
The result is a WordPress landscape where WordPress markup and styles are ... Standardizing theme.json design token naming conventions and ...
Read more >Modern CSS Techniques To Improve Legibility
In this article, we cover how we can improve websites legibility using some modern ... On design systems, UX, web performance and CSS/JS....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Regarding “HTML: Treating quotes and equals differently than normal punctuation”:
Another CSS-based solution is to use the fact that the
=
character will always be the first token inside aattr-value
token. So the following to uniquely identify every=
character:Regarding the quotes:
I have 2 possible solutions: 1. Add a hook which gives the first
=
a special class. Change the style ofattr-value
to look the same as strings and overwrite the color for the=
using the special class.Not tested but should work. This will also affect the
=
signs of all other languages but that shouldn’t be too much of a problem.The second solution is to modify the markup language definition:
I would careful with modifying the language definition because my other languages rely on markup, so this might cause problems.