This commit is contained in:
Panagiotis Papadopoulos 2025-03-02 08:48:32 +01:00
parent 1dc5452cd0
commit 85df5c3297

View File

@ -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 //close tag
indent = indent.substr(0, indent.length - 1); if (x.includes("</")) {
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + x.substr(x.length - 1, x.length); indent = indent.slice(0, -1);
else ret = indent + x; return (!x.endsWith(">"))
? indent + x.slice(0, -1) + indent + x.slice(-1)
: indent + x;
} }
// open tag
if (!tempPreIdxMatch) {
indent += tab;
} }
return ret;
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--; ) {