Add initHighlight callable multiple times.
See original GitHub issueAdd a variant of initHighlight
function that can be called multiple times. Useful for single-page applications with lazy-loaded content, that don’t wish to specifically target new code blocks and highlight them manually.
Currently this can be accomplished as follows:
hljs.initHighlighting.called = false;
hljs.initHighlighting();
But that seems bad practice as it’s more complicated than necessary, and encourages manipulation of an internal variable.
We could do:
hljs.initHighlighting(true);
But some might not like the boolean trap. In which case, we could do:
hljs.initHighlighting({force: true});
or:
hljs.initHighlighting({once: false});
Thoughts? I can submit a pull request.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Advice on how to make a javascript function callable multiple ...
Basically, I want to try to call several instances of this slider in my HTML document. I have tried wrapping the function inside...
Read more >Diff - gerrit - Google Git
If a merge +is necessary yet we already have this many threads running, the incoming thread +(that is calling add/updateDocument) will block until...
Read more >Collaborative JavaScript Debugging - JS Bin
A live pastebin for HTML, CSS & JavaScript and a range of processors, including SCSS, CoffeeScript, Jade and more...
Read more >PEP 677 – Callable Type Syntax
We can add types to this example to detect the runtime error: ... There are a few usability challenges with Callable we can...
Read more >File: elpy.el - Debian Sources
Elpy creates RPC buffers over time, depending on python interpreters and ... Elpy can automatically insert parentheses after completing callable objects.
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
No, not really. While the desire to highlight new code blocks is pretty straight-forward the details would differ: people use millions of different frameworks with different tools for reacting at new code blocks. Resorting to some global function that does or does not what you want is far less convenient than just calling
highlightBlock
orhighlightAuto
on new content. This also takes care of filtering out already highlighted elements.And if you do want such a function in your particular case it’s a simple two-liner, really:
So I’d say
highlightBlock
is an adequate API and adding wrappers around it is a slippery slope of chasing all the slightly different variants that people would want.+1