mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Switch highlight plugin under Node.js to use DOM rather than raw HTML
Hi @welford I wondered if you could kindly review this commit, since you authored the original code? Before this commit, I was running into a crash when running `prerelease-bld.sh` from `build.jermolene.github.io`, caused by using raw HTML for the highlighted block. Switching to the fake dom seems to fix things, but I’d like a second pair of eyes.
This commit is contained in:
parent
292d653880
commit
4be5f0abe8
@ -27,15 +27,11 @@ CodeBlockWidget.prototype.postRender = function() {
|
||||
if(tiddler) {
|
||||
language = tiddler.fields.text || "";
|
||||
}
|
||||
if($tw.browser && this.document !== $tw.fakeDocument && language) {
|
||||
domNode.className = language.toLowerCase();
|
||||
hljs.highlightBlock(domNode);
|
||||
} else if(!$tw.browser && language && language.indexOf("/") === -1 ){
|
||||
if(language) {
|
||||
try {
|
||||
domNode.className = language.toLowerCase() + " hljs";
|
||||
domNode.children[0].innerHTML = hljs.fixMarkup(hljs.highlight(language, this.getAttribute("code")).value);
|
||||
}
|
||||
catch(err) {
|
||||
hljs.highlightBlock(domNode);
|
||||
} catch(err) {
|
||||
// Can't easily tell if a language is registered or not in the packed version of hightlight.js,
|
||||
// so we silently fail and the codeblock remains unchanged
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user