fix(cmake): only highlight standalone numbers, not digits in identifiers - #4438
Merged
joshgoebel merged 3 commits intoJul 17, 2026
Merged
Conversation
The default number mode matched a leading digit even when it was the start of an identifier, so the `3` in `add_subdirectory(3rdparty/foo)` was highlighted as a number. Override the number mode with a `begin` pattern that requires a trailing word boundary (`/\b\d+(\.\d+)?\b/`) so only real, standalone numbers are matched. Closes highlightjs#4170
joshgoebel
reviewed
Jul 15, 2026
| hljs.QUOTE_STRING_MODE, | ||
| hljs.NUMBER_MODE | ||
| { | ||
| className: 'number', |
Member
There was a problem hiding this comment.
Suggested change
| className: 'number', | |
| scope: 'number', |
joshgoebel
reviewed
Jul 15, 2026
| // require a word boundary so digits that merely begin an | ||
| // identifier (e.g. the `3` in `3rdparty`) are not highlighted | ||
| begin: /\b\d+(\.\d+)?\b/, | ||
| relevance: 0 |
Contributor
Author
|
Thanks for the review! Both addressed in 03f30a9 — switched to |
joshgoebel
approved these changes
Jul 17, 2026
Build Size ReportChanges to minified artifacts in 2 files changedTotal change +55 B View Changes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the CMake grammar so a digit at the start of an identifier is no longer highlighted as a number. For example, in:
the leading
3of3rdpartywas being wrapped in ahljs-numberspan.Why
src/languages/cmake.jsusedhljs.NUMBER_MODE, whosebegin(\b\d+(\.\d+)?) has only a leading word boundary, so it matched the3inside3rdparty. This matches the fix suggested by the maintainer in the issue: use a number mode with a trailing\bas well.How
Replaced
hljs.NUMBER_MODEwith an inline mode:Testing
test/markup/cmake/fixture withadd_subdirectory(3rdparty/foo)and the expected markup where3is not wrapped in a number span.ONLY_LANGUAGES=cmake mocha test/markup).2.8.8) is unchanged.CHANGES.mdentry.Closes #4170