enh(css-like) custom attributes should highlight as `attr`, including the `--`
See original GitHub issueHello and thanks for this amazing library! I am using it for my blog to highlight code snippets, and recently I used CSS highlighting on a code example which included CSS variables.
More specifically I have this case:
/* default context vars */
body {
--color: black;
--background-color: lightgrey;
}
/* dark theme context vars */
body.dark {
--color: lightgrey;
--background-color: black;
}
/* selector with styles using vars */
main {
color: var(--color);
background-color: var(--background-color);
transition: background-color 0.2s ease-in-out;
}
The output looks like this:
Normally, I would expect that the prefixing --
of the variables would have been handled as part of the attribute.
I am thinking of forking this repo to introduce a PR addressing this issue. What do you think?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Attribute selectors - CSS: Cascading Style Sheets | MDN
The CSS attribute selector matches elements based on the presence or value of a given attribute.
Read more >The CSS attr() function got nothin' on custom properties
CSS custom properties! You can pop them right into the style attribute of any element. Now those values are available to that element:...
Read more >HTML5 Custom Attributes And How To Access Them Using ...
You will also learn how to access/read custom (data) attributes with CSS, using the function attr (), also you will learn how to...
Read more >Lesson 1: Understanding ID and Class in CSS
In this lesson you will learn how ID and Class attributes can be used to stylize individual elements ... You assign an id...
Read more >Can I add a custom attribute to an HTML tag? - Stack Overflow
You can add custom attributes to your elements at will. But that will make your document invalid. In HTML 5 you will have...
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
Since
var
is already highlighted (as a function like thingy) and pops I’m inclined to say it can remain unhighlighted (as GitHub is doing) rather than highlighting bothvar
and the name.So what I think needs to happen here:
--custom-property
, now highlighting the--
as well… and doing so asattr
vsattribute
.tools/css
and thecss_consistency
markup testsAccording to MDN docs, it sounds to me like
--
along with the name is the custom property; it’s not that--
is separate from the property name. Based off that, I think--my-variable
should be highlighted as a single entity (e.g. “variable”) in a ruleset and inside of avar()
call.Considering that these are “custom properties”, they’re no different from any other CSS property. So I think they should be highlighted with the same class name and have an additional class like
variable
orcustom-property
or whatever if themes want to opt-in to changing their colors.