-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
JS - change CLASS_REFERENCE regex to also accept numbers and underscore #3255
Conversation
Adding a markup test for this case to |
What do you think? @joshgoebel |
I appreciate the quick fix, but is There are a few problems that I can see here:
I think those points above could be addressed with something like It's also missing unicodes, but this may be a bit beyond the scope of this change. This stack overflow answer has a complete solution, but not what highlight.js needs, because builtins seem to be cleared up before). |
This is a conventions rule, not an absolute one. Uppercase classes is a hugely common convention, but a lowercase symbol could be anything. That said if someone wanted to add a mode specifically for
This should indeed be taken into account. So we need a few more markup tests.
This seems an edge case and same problem as first point, false positives.
Ditto. Unless I'm missing something about grouping, the first + is wrong and the (....+)* could be replaced by *. Good point, but the whole thing may need to be slightly rethought now to handle cases like |
@rbrishabh You need to actually run the test suite, and update the test expectations also, etc... see our docs for building and testing. Now we also need to add test for class names like |
Sure! I can look into this later today! |
hey @joshgoebel! How does this look now? |
…ight.js into CLASS_REFERENCE-js-regex
@@ -252,7 +252,7 @@ export default function(hljs) { | |||
|
|||
const CLASS_REFERENCE = { | |||
relevance: 0, | |||
match: /\b[A-Z][a-z]+([A-Z][a-z]+)*/, | |||
match: /\b[A-Z][A-Za-z0-9_]+/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okey, although technically it should be *
and not +
(otherwise new X()
won't work). But I'm not sure if this breaks some other logic on HighlightJS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one letter class names is an edge case. We really want to see the camel case pattern to trigger this heuristic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's focus more on the tests... at the very end I might take one last look and tweak this a variety of diff ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need BOTH... I played with this briefly.
CRV
with zero context could be a constant (all CAPS is a constant) or a class name... Changing this rule as it is now incorrectly identifies constants as classes (or vice versa)... I think perhaps we need to handle both:
CRV
(constant)CRV(
(class)
It's not perfect, but we can't get perfect since these are conventions, not language rules. So we'd use the camel case rule (with zero other context) PLUS the newer new rule proposed here, but only if a look-ahead sees a (
. I think that would cover a lot of cases. Thoughts?
I'm still looking for an updated |
Ping. |
hi! I have a busy schedule and cant keep up with this now! Please feel free to continue it from here. I can close it for now |
Thanks anyways! It'll be here if anyone needs to reference it when there is time to pick this back up. |
fixes #3252
Hey @joshgoebel! How does this look?
Let me know if this needs any changes! Thanks