Open gusbemacbe opened 4 years ago
CSS elements
I think you mean values. The only "elements" in CSS are element selectors.
To tokenize every valid CSS value, we have to know every valid CSS value and there are quite a few. Here's VSCode's CSS LS' list of values by property. After extracting all values and some filtering, I'm left with a list of ~500 values that will make a 6.1k characters long regex. The file sizes of CSS and CSS extras are ~1kB and ~3kB respectively. That's quite an increase in file size. And then there's also the issue of maintainability.
The easiest solution here is to set the default text color to the color you want CSS values to have. Not perfect but it comes close to your goal.
The
px
should remain pink.
With CSS extras, all units are tokenized as .token.unit
. That should help.
CSS properties
I'll add something for and
, or
, not
, and only
.
@ rules
You can use .token.atrule > .token.rule
to given the @name
part a specific color.
CSS URL values
This should be rather easy to implement by adding a string token for string values.
Also observe that parentheses
(
and)
should remain purple [...]
In one of the above screenshots, parentheses are yellow. You probably have a rainbow braces extension installed, right? You can use Match braces to implement this.
I'll make a PR for the promised changes.
@RunDevelopment
The easiest solution here is to set the default text color to the color you want CSS values to have. Not perfect but it comes close to your goal. Details For those, interested. This is the regex:
I did not see red
and other colour names and codes, etc. as part of this regex.
All colors are part of CSS extras.
I tried to figure out how I manipulated the CSS codes, using a value's regex for .language-css
, but it is impossible in CSS file. I have to use JavaScript.
Sorry, I don't understand what you mean by "how I manipulated the CSS codes"?
@RunDevelopment
For example:
.languace-css [\-ms-inline-flexbox\][\-ms-inline-grid\]
{
}
Ahh, so you want to style tokens differently depending on their text content.
Yes, you will need JavaScript for that. You can use the Custom class plugin to accomplish that:
Prism.plugins.customClass.add(({content, type, language}) => {
if (content.startsWith('-ms-') && type === 'value' && language === 'css') {
return 'ms-value'; // add the `ms-value` class to all matching tokens
}
});
Ahh, so you want to style tokens differently depending on their text content.
Yes, you will need JavaScript for that. You can use the Custom class plugin to accomplish that:
Prism.plugins.customClass.add(({content, type, language}) => { if (content.startsWith('-ms-') && type === 'value' && language === 'css') { return 'ms-value'; // add the `ms-value` class to all matching tokens } });
Actually, I want to apply all these token, not just ms-
. Is it possible that this new custom Prismjs plugin match the patterns from a text file?
Look, you do not need to add that to Prismjs project. I will add this custom class plugin only to Dracula Prismjs project.
I want to apply all these token
Which tokens? .value
tokens?
Maybe we should take a step back: From my understanding, you want to highlight CSS values and you also want to highlight some CSS values differently, right? I assume that you already made some modifications to Prism's CSS language definition to add a value
token for CSS values (regex above) because you can only highlight tokens with CSS.
There are two ways to highlight certain CSS values differently: The first way is what I described above. Use the Custom class plugin to add a marker-class to some tokens. However, Custom class is intended to be used if you don't want to (or can't) modify any language definitions but we can. So instead of modifying the CSS language definition like this:
Prism.languages.css.value = /\b(?:foo|bar|...)\b/;
We can split out the list of values directly like this:
Prism.languages.css.value = [
{
// this will produce `.token.value.foo-class` tokens
pattern: /\b(?:foo)\b/,
alias: 'foo-class'
},
// this will produce `.token.value` tokens
/\b(?:bar|...)\b/
];
Look, you do not need to add that to Prismjs project.
Yes, that wasn't my intention.
Motivation
It seems that Prismjs does not have CSS element. CSS elements are white, but in the Dracula theme, it is purple.
Description
In reference to dracula/prism#11, I followed the Dracula's specific documentation. Imitating and mimicking the CSS syntax highlighting in VSCode, there are two differences between Prism's HTML and VSCode's HTML syntax highlightings. See the alternatives with solutions:
Alternatives
CSS elements
Using Dracula theme, compare CSS elements, entirely highlighted as white by the class
.language-css
in Prismjs, but in VSCode, it is different:Dracula:
Prismjs:
Observation: The
px
should remain pink.CSS properties
The property
screen and
is dominated by the class.language-css .token.atrule
,and
has different colours in Dracula and Prismjs themes.Dracula:
Prismjs:
@ rules
Not just
@main-color
, the class.language-css .token.rule
also takes control of@media
which must remain purple. Observe that@media
belongs to the class.language-css .token.atrule
.Dracula
Prismjs
I tried this CSS:
CSS URL values
In Dracula, the values without quotation marks remain orange, but with quotation mark, they are highlighted as yellow. In Prismjs, both the values without and with quotation marks are dominated by the class
.language-css .token.url
. Also observe that parentheses(
and)
should remain purple if the regular expression findsurl
.Dracula
Prismjs