question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

enh(css-like) custom attributes should highlight as `attr`, including the `--`

See original GitHub issue

Hello 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:

Screenshot 2021-06-11 at 10 05 44 AM

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:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
joshgoebelcommented, Jun 13, 2021

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 both var and the name.

So what I think needs to happen here:

  • Scope of PR is reduced to just fixing the highlighting issue with --custom-property, now highlighting the -- as well… and doing so as attr vs attribute.
  • This change needs to be applied to SCSS, Stylus, and Less grammars also as originally mentioned.
    • See tools/css and the css_consistency markup tests
    • Only a single small example need to added.
1reaction
allejocommented, Jun 12, 2021

Declaring a custom property is done using a custom property name that begins with a double hyphen (--)

According 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 a var() 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 or custom-property or whatever if themes want to opt-in to changing their colors.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found