Skip to content
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

enh(parser) better regular expression detection #2380

Merged
merged 3 commits into from Feb 6, 2020

Conversation

joshgoebel
Copy link
Member

@joshgoebel joshgoebel commented Feb 1, 2020

  • fewer false positives
  • Uses a look-ahead to make sure we have a WHOLE regex and not
    just a partial (which is more likely a math expression)

Closes #2050.

- fewer false positives
- Uses a look-ahead to make sure we have a WHOLE regex and not
  just a partial (which is more likely a math expression)
@joshgoebel
Copy link
Member Author

joshgoebel commented Feb 1, 2020

This paired with the "value" container support (and smart rule ordering) in JS actually catches a lot of common cases:

`Bad ${foo / 1000}`
foo = 2 / 2 + 2 / 2;
foo = / 2 + 2 /;
b = a++ / 2;

All of these just work (which is even better than Github). So I think this is enough to close that issue until we have more real life examples that fail (new issues), and then review this again.

@joshgoebel joshgoebel added enhancement An enhancement or new feature parser labels Feb 1, 2020
@joshgoebel joshgoebel added this to the 10.0 milestone Feb 1, 2020
Copy link
Collaborator

@egor-rogov egor-rogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty cool!

@joshgoebel joshgoebel merged commit 11fcaea into highlightjs:master Feb 6, 2020
taufik-nurrohman pushed a commit to taufik-nurrohman/highlight.js that referenced this pull request Feb 18, 2020
* enh(parser) better regular expression detection

- fewer false positives
- Uses a look-ahead to make sure we have a WHOLE regex and not
  just a partial (which is more likely a math expression)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(javascript) division and regular expressions can get confused and break highlighting
2 participants