Update number pattern to catch variables containing numbers#3648
Conversation
|
Awesome contribution! Great tests. Sadly, we can't use look-behinds, they aren't yet supported universal by all browsers (ie: Safari). Typically for things like this you'd instead try to match the offending item... ie, add an earlier rule to match/capture |
|
Yes. Adding |
We don't need a-z though since all we're trying to solve is the false-positive with |
|
OK. FYI, this also happen in default JacaScript’s syntax highlighter in Vim. |
I thought about this, but used it since there are two other |
|
Two other tests? Where? |
|
Nevermind, did a cursory search and found this, but didn't notice it was a comment. highlight.js/src/languages/r.js Lines 173 to 176 in abcb53d I will update with the suggested pattern! |
|
Ok, this has been updated. I did have to leave the - actual
+ expected
-<span class="hljs-keyword">const</span> result = $<span class="hljs-title function_">class</span>();
+<span class="hljs-keyword">const</span> result = $class(); |
Isn't that because you are using * when it should be +?
We don't care about just plain $ unless it's followed by variable like stuff... All you're really trying to skip is |
|
Yes, fair point. Thanks for clarifying. Updated pattern and merged upstream. |
|
Oh, you made it a variant..... :-). Interesting. I'll fix. |
|
Yeah, took reference from here: highlight.js/src/languages/python.js Lines 332 to 338 in e0f7577 |
Yeah, but that example sort of IS still an instance of params, just "empty params"... where as $123 isn't really an instance of a numeric, it's a variable. :-). I'm being pedantic now. But what you're doing is one easy way to get that rule in all the same spots you'd want the NUMBER rule (which is convenient)... so that's an argument for it... so I might just revert and commit your last revision after all. :-) |
|
Gotcha, I understand. I've moved it to before the both uses of Thanks for the time and input! |
Currently, numbers are matched based on the word boundary (
\b) but that means that a valid variable identifier like$0will have the0highlighted as a number.Resolves #3645
Changes
$symbol.Checklist
CHANGES.md