highlight.js: Uncaught SyntaxError: Invalid regular expression: ... when add "java" in language array
I found that when I don’t specify any language or specify “java” in language array then I get following error
highlight.pack.js:2 Uncaught SyntaxError: Invalid regular expression: /([À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*(<[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*(\s*,\s*[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*)*>)?\s+)+[a-zA-Z_]\w*\s*\(/: Range out of order in character class
at new RegExp (<anonymous>)
at t (chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:1738)
at r (chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:2177)
at chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:2468
at Array.forEach (native)
at r (chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:2448)
at s (chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:2670)
at l (chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:4157)
at chrome-extension://ieokebkfhmgbnhlmnijfgcdkbieibipc/quill/modules/highlight/highlight.pack.js:2:4651
at Array.forEach (native)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 16 (5 by maintainers)
Commits related to this issue
- talk: fix highlight.js regex error ack: https://github.com/highlightjs/highlight.js/issues/1387#issuecomment-354565414 — committed to dckc/RChain-API by dckc 6 years ago
- talk: toward reveal.js slides took 3hrs to get this far; lots of fiddling with reveal.js for 3hrs struggled with https://github.com/highlightjs/highlight.js/issues/1387 etc. — committed to dckc/RChain-API by dckc 6 years ago
- workaround for errors thrown from latest version of highlight.js https://github.com/highlightjs/highlight.js/issues/1387 — committed to janoside/btc-rpc-explorer by janoside 5 years ago
- index.html: specify UTF-8 charset Without this, we encounter weird crashes in highligh.js. See e.g. https://github.com/highlightjs/highlight.js/issues/1387 — committed to mwilck/labsconf2021 by mwilck 3 years ago
- index.html: specify UTF-8 charset Without this, we encounter weird crashes in highligh.js. See e.g. https://github.com/highlightjs/highlight.js/issues/1387 — committed to mwilck/labsconf2021 by mwilck 3 years ago
- index.html: specify UTF-8 charset Without this, we encounter weird crashes in highligh.js. See e.g. https://github.com/highlightjs/highlight.js/issues/1387 — committed to SUSE/presentation-template by mwilck 3 years ago
- workaround for errors thrown from latest version of highlight.js https://github.com/highlightjs/highlight.js/issues/1387 — committed to robust34/btc-rpc-explorer by robust34 5 years ago
This appears to be a character encoding problem with the browser that is loading your page. It is not using UTF-8 by default. I was able to fix it by making sure I had UTF-8 in the meta tag of the HTML page that is using highlightjs: < meta charset=“utf-8” >
Add that to your document’s head and see if that solves it for you.
i have same issue
Not sure if it helps but:
This build at cdnjs seems to have the problem:
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>And not this one:
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.13.1/build/highlight.min.js"></script>Wondering if it’s a hosting encoding problem. ¯_(ツ)_/¯
You can also do:
to overcome the encoding issue.
guys just change java id regex… someone need to fix the bug at https://github.com/isagalaev/highlight.js/blob/master/src/languages/java.js (line: 8) until then you can just search for: ‘
hljs.registerLanguage("java"’ in your highlight.pack.js then change:hljs.registerLanguage("java",function(e){var a="[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*"to anything that suite your needs, for me I don’t need UTF-8 chars so I m using a simple regex:hljs.registerLanguage("java",function(e){var a="[a-zA-Z_$][a-zA-Z_$0-9]*"(I hope that I didn’t just broke the copyright of this api >_<)