mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Tentative improvements to highlight plugin problems
We now use highlight.js in raw HTML mode on the server, rather than trying to use it with the fakedom. This causes problems with fakedoms inability to get textContent for a node that has been created by assigning innerHTML. So we extend the fakedom to allow the original text content to be saved. See #2778 for discussion.
This commit is contained in:
parent
eee18aab40
commit
b1ecf81b0c
@ -206,13 +206,29 @@ Object.defineProperty(TW_Element.prototype, "innerHTML", {
|
||||
set: function(value) {
|
||||
this.isRaw = true;
|
||||
this.rawHTML = value;
|
||||
this.rawTextContent = null;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(TW_Element.prototype, "textInnerHTML", {
|
||||
set: function(value) {
|
||||
if(this.isRaw) {
|
||||
this.rawTextContent = value;
|
||||
} else {
|
||||
throw "Cannot set textInnerHTML of a non-raw TW_Element";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(TW_Element.prototype, "textContent", {
|
||||
get: function() {
|
||||
if(this.isRaw) {
|
||||
if(this.rawTextContent === null) {
|
||||
console.log(booboo)
|
||||
throw "Cannot get textContent on a raw TW_Element";
|
||||
} else {
|
||||
return this.rawTextContent;
|
||||
}
|
||||
} else {
|
||||
var b = [];
|
||||
$tw.utils.each(this.children,function(node) {
|
||||
|
@ -28,12 +28,16 @@ CodeBlockWidget.prototype.postRender = function() {
|
||||
language = tiddler.fields.text || "";
|
||||
}
|
||||
if(language) {
|
||||
try {
|
||||
domNode.className = language.toLowerCase() + " hljs";
|
||||
if($tw.browser && !domNode.isTiddlyWikiFakeDom) {
|
||||
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
|
||||
} else {
|
||||
var text = domNode.textContent;
|
||||
domNode.children[0].innerHTML = hljs.fixMarkup(hljs.highlight(language,text).value);
|
||||
// If we're using the fakedom then specially save the original raw text
|
||||
if(domNode.isTiddlyWikiFakeDom) {
|
||||
domNode.children[0].textInnerHTML = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user