mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
WIP
This commit is contained in:
parent
1dc5452cd0
commit
85df5c3297
@ -81,34 +81,36 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget {
|
|||||||
pre.push({ indent: "", tag: match });
|
pre.push({ indent: "", tag: match });
|
||||||
return `<--TEMPPRE${i++}/-->`;
|
return `<--TEMPPRE${i++}/-->`;
|
||||||
})
|
})
|
||||||
.replace(new RegExp("<[^<>]+>[^<]?", "g"), function (x) {
|
.replace(new RegExp("<[^<>]+>[^<]?", "g"), (x) => {
|
||||||
let ret;
|
const tagMatch = /<\/?([^\s/>]+)/.exec(x);
|
||||||
const tagRegEx = /<\/?([^\s/>]+)/.exec(x);
|
let tag = tagMatch ? tagMatch[1] : "";
|
||||||
let tag = tagRegEx ? tagRegEx[1] : "";
|
let tempPreIdxMatch = new RegExp("<--TEMPPRE(\\d+)/-->").exec(x);
|
||||||
let p = new RegExp("<--TEMPPRE(\\d+)/-->").exec(x);
|
|
||||||
|
|
||||||
if (p) {
|
if (tempPreIdxMatch) {
|
||||||
const pInd = parseInt(p[1]);
|
const tempPreIdx = parseInt(tempPreIdxMatch[1]);
|
||||||
pre[pInd].indent = indent;
|
pre[tempPreIdx].indent = indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selfClosingTags.has(tag)) {
|
if (selfClosingTags.has(tag)) {
|
||||||
// self closing tag
|
return indent + x;
|
||||||
ret = indent + x;
|
|
||||||
} else {
|
|
||||||
if (x.indexOf("</") < 0) {
|
|
||||||
//open tag
|
|
||||||
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + tab + x.substr(x.length - 1, x.length);
|
|
||||||
else ret = indent + x;
|
|
||||||
!p && (indent += tab);
|
|
||||||
} else {
|
|
||||||
//close tag
|
|
||||||
indent = indent.substr(0, indent.length - 1);
|
|
||||||
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + x.substr(x.length - 1, x.length);
|
|
||||||
else ret = indent + x;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
//close tag
|
||||||
|
if (x.includes("</")) {
|
||||||
|
indent = indent.slice(0, -1);
|
||||||
|
return (!x.endsWith(">"))
|
||||||
|
? indent + x.slice(0, -1) + indent + x.slice(-1)
|
||||||
|
: indent + x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open tag
|
||||||
|
if (!tempPreIdxMatch) {
|
||||||
|
indent += tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (!x.endsWith(">"))
|
||||||
|
? indent + x.slice(0, -1) + indent + tab + x.slice(-1)
|
||||||
|
: indent + x;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (i = pre.length; i--; ) {
|
for (i = pre.length; i--; ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user