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) Escaped special character in selector class name breaks highlighting #3965

Open
sentience opened this issue Jan 16, 2024 · 2 comments · May be fixed by #4104
Open

(css) Escaped special character in selector class name breaks highlighting #3965

sentience opened this issue Jan 16, 2024 · 2 comments · May be fixed by #4104
Labels
bug help welcome Could use help from community language

Comments

@sentience
Copy link

sentience commented Jan 16, 2024

Describe the issue

CSS class and ID selectors contain arbitrary strings (e.g. .myclassname), which can contain escaped special characters (e.g. .foo\:myclassname to match class="foo:myclassname"). Currently, the backslash that escapes a special character is not recognised by highlight.js as a valid part of the class name or ID.

Which language seems to have the issue?

css

Are you using highlight or highlightAuto?

highlight

Sample Code to Reproduce

.dark\:hover\:bg-sky-500:hover {
  --tw-bg-opacity: 1;
  background-color: rgb(14 165 233 / var(--tw-bg-opacity));
}

Current highlighting:

CleanShot 2024-01-16 at 11 45 54

Expected behavior

The escaped special characters (\:) should not interfere with the highlighting of the class name, but actual pseudoclasses (:hover) should still be highlighted.

GitHub:

CleanShot 2024-01-16 at 11 43 34

VS Code:

CleanShot 2024-01-16 at 11 45 17

Additional context

TailwindCSS makes extensive use of escaped characters in CSS selectors for its modifiers.

Other special characters are escaped for features like color opacity:

.dark\:hover\:bg-sky-500\/25:hover {
  background-color: rgb(14 165 233 / 0.25);
}

…and arbitrary values:

.dark\:hover\:bg-\[\#ff0000\]\/25:hover {
  background-color: rgb(255 0 0 / 0.25);
}
@sentience sentience added bug help welcome Could use help from community language labels Jan 16, 2024
@joshgoebel
Copy link
Member

Probably need to push a proper CLASS_NAME_RE down into css-shared.js where it can then be shared with all the css-like grammars.

Anyone wanting to pick this up will need to take a look at tools/css. (helps with CSS testing). We require that all our css-like grammars remain consistent, so a patch here would need to fix all 4 grammars, not just CSS.

A PR would be welcome.

@Dxuian
Copy link
Contributor

Dxuian commented Aug 29, 2024

i bei

Probably need to push a proper CLASS_NAME_RE down into css-shared.js where it can then be shared with all the css-like grammars.

Anyone wanting to pick this up will need to take a look at tools/css. (helps with CSS testing). We require that all our css-like grammars remain consistent, so a patch here would need to fix all 4 grammars, not just CSS.

A PR would be welcome.

i believe i have a fix for this please review @joshgoebel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
3 participants