-
Notifications
You must be signed in to change notification settings - Fork 743
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
Add disambiguation for C++ header files #1269
Add disambiguation for C++ header files #1269
Conversation
C++ header files can use the `.h` extension. By default, Rouge highlights these files with the C lexer. This can lead to incorrect highlighting because certain keywords in C++ are not reserved in C. A similar situation can occur with Objective-C files but Rouge provides a disambiguation for Objective-C files to avoid this problem. This commit adds a similar disambiguation for C++.
The list of keywords could be improved.
and probably more Whether these keywords should be used for detection, I don't know. |
@eliaskosunen Thanks for the quick reply! Would some of those really begin a line in a header file (eg. |
Headers can contain struct S {
void foo() {
try { // `try` as the first word of a line
bar(
this); // `this` as the first word of a line
} catch(...) {
// ...
}
}
}; Should you want to stay conservative, in the least I think you should have, in addition of what you listed, |
@eliaskosunen Ah, forgot about inline function definitions. Hmmm... I think what I'd like to do at this point is release this fix and see how it goes in everyday use. What do you think? |
This would certainly be better than what we have now. |
@eliaskosunen Thanks for your help on this. We're on a two-week release cadence at the moment as we work through the backlog so this will go out as part of v3.8.0 on Tuesday 6 August. I'm not affiliated with GitLab at all so am not sure when they'll switch over to using it so you might want to check with them. |
@eliaskosunen Back when I worked for Gitlab, I implemented this, which may be of interest to you: https://docs.gitlab.com/ce/user/project/highlighting.html You can specify the language for any glob of files. |
C++ header files can use the
.h
extension. By default, Rouge highlights these files with the C lexer. This can lead to incorrect highlighting because certain keywords in C++ are not reserved in C. A similar situation can occur with Objective-C files but Rouge provides a disambiguation for Objective-C files to avoid this problem. This commit adds a similar disambiguation for C++.This fixes #932.