Cannot read property 'replace' of undefined(..) when calling highlightBlock() or highlightAuto()
See original GitHub issueWhen I call hljs.highlightBlock();
or hljs.highlightAuto();
I get this error: Cannot read property 'replace' of undefined(..)
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
[SOLVED] Cannot Read Property 'replace' of Undefined in JS
This error occurs when you attempt to call the replace() method on a variable that has a value of undefined . const str...
Read more >TypeError: Cannot read property 'replace' of Undefined in JS
The "Cannot read property 'replace' of undefined" error occurs when calling the replace() method on a variable that stores an undefined value.
Read more >How to use highlight.js
The bare minimum to auto-detect the language and highlight some code. // load the library and ALL languages hljs = require('highlight.js'); html =...
Read more >TypeError: Cannot read property 'replace' of undefined
I have been trying to make my first express application and I have been getting a error with range.replace() ...
Read more >Core API — highlight.js 11.7.0 documentation - Read the Docs
highlightAuto (code, languageSubset). Highlighting with language detection. Accepts a string with the code to highlight and an optional array of language ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah… This doesn’t work because
hljs.initHighlighting
only works once. To highlight anything dynamically you callhljs.highlightBlock
on specific code blocks. It’s okay to lethljs.initHighlighting
work on$(document).read
but onpjax:end
you should first figure out which blocks arent’ highlighted yet:I haven’t tested the code, it’s just to show the idea.
And your original code didn’t work because
hljs.highlightAuto
is a lower level function that accepts code as a simple string, not a DOM node.I think it’s safe to close by now, as it’s obviously not a bug with either of the methods mentioned.