highlightjs / highlightjs/highlight.js

(C and C++) Defines treat digit separator in defines as string beginning

Open
#4,443 0 comments 0 reactions 0 assignees View on GitHub
bug help welcome language
Dominant language
JavaScript
Stars
25k
Forks
3.8k
Avg merge
11h 35m
Merged PRs (30d)
3

Description

**Describe the issue**

```c
#define FOO 10'000
```

is valid code, using `'` as a digit separator. Highlight.js incorrectly treats it as a beginning of a string.

Image

**Which language seems to have the issue?**

I tested C and C++, both get it wrong.

**Are you using `highlight` or `highlightAuto`?**

No clue. I originally noticed the issue while sending code over Discord and confirmed it again with [your demo](https://highlightjs.org/demo). I did select the language manually in both cases.

**Expected behavior**

The `'` character should be treated as part of the number.

**Additional context**

Support for this separator has been around in C++ since C++14, but it's relatively new in C, added in C23.

Contributor guide

Open the contributing guide

Research direction

Start with the C and C++ language definitions and reproduce the reported `#define FOO 10'000` case in the Highlight.js demo. Done means the apostrophe is highlighted as part of the number in both languages, rather than as the beginning of a string.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.