highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(C++) highlight incorrectly

Open zerolfx opened this issue 3 years ago • 3 comments

Describe the issue

Screenshot_20220320_225211

Everything after the define line has no highlighting.

Which language seems to have the issue?

C++

Are you using highlight or highlightAuto?

highlight.js 11.5.0

Sample Code to Reproduce

int a = 1;

#define what do { cout << ">"; } while (0)

int main() {
}

Expected behavior

Highlight correctly after the define line.

zerolfx avatar Mar 21 '22 02:03 zerolfx

I found this bug introduced at #3041. @joshgoebel. <.*> matches << "> and leaves " alone. All preprocessor keywords are treated as meta-keywords. But only #include needs to be followed with angle bracket quoted string. PREPROCESSOR in cpp.js/c.js might be subdivided to deal with different scenarios. Or simply change <.*> into <[^"]*>. The latter would contradict the lexical rule mentioned in http://eel.is/c++draft/lex.header, though I think people won't use " in their header file name...

adobemomo avatar Mar 21 '22 07:03 adobemomo

You may be right that this needs to be scoped to #include...

joshgoebel avatar Mar 21 '22 12:03 joshgoebel

Either of your willing to submit a PR for this?

joshgoebel avatar Jun 27 '22 19:06 joshgoebel