Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CSS) custom property --_margin-top: 1rem, top gets wrongly highlighted #3823

Closed
miragecraft opened this issue Jul 17, 2023 · 5 comments
Closed
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@miragecraft
Copy link

Describe the issue

In CSS, custom property such as --_margin-top: 1rem, top gets wrongly highlighted

It seems to be caused by some kind of interaction between the underscore and hyphen.

Which language seems to have the issue?

CSS, I'm using language="css" and NOT using auto-detect.

Sample Code to Reproduce

.example {
    --_margin-top: 1rem;
}

Expected behavior

--_margin-top should be treated as an atomic unit of text for highlighting purposes.

@miragecraft miragecraft added bug help welcome Could use help from community language labels Jul 17, 2023
@joshgoebel
Copy link
Member

joshgoebel commented Jul 18, 2023

- is a word boundary (\b), so the rule matches:

      {
        scope: 'attribute',
        match: '\\b(' + css.ATTRIBUTES.join('|') + ')\\b'
      },

One fix here might be to use a multi-matcher. (example: https://highlightjs.readthedocs.io/en/latest/mode-reference.html#beginscope). You'd first match \s (with no scope) and then match the attribute... that's the closest we can currently get to a look-behind, which we don't support yet because Safari is still slow to that party.

Once we could use lookbehind you'd just do a lookbehind for "not space" instead of \b...

A PR would be welcome here if you hav time.

@joshgoebel joshgoebel added the good first issue Should be easier for first time contributors label Jul 18, 2023
akhtarmdsaad added a commit to akhtarmdsaad/highlight.js that referenced this issue Sep 19, 2023
@akhtarmdsaad akhtarmdsaad mentioned this issue Sep 19, 2023
2 tasks
@Harsh3363
Copy link

Hi @joshgoebel I would like to solve this issue please assign this to me

@joshgoebel
Copy link
Member

We don't usually do assignments, but I don't think anyone is rushing to complete this before you do. Happy to see a PR if you contribute one.

joshgoebel pushed a commit to akhtarmdsaad/highlight.js that referenced this issue Oct 8, 2023
@SamiKamal
Copy link

I think this should be closed as it was solved in #3863

@miragecraft
Copy link
Author

Looks like it's fixed in the official site's demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

4 participants