Update Core.js

This commit is contained in:
simonpipe 2026-07-09 19:16:59 +02:00
parent 069665dc61
commit 90d5e24b1a

44
Core.js
View file

@ -130,7 +130,7 @@ class SimonUp {
}
tocWrapper += '\n</div>';
}
return tocWrapper;
return tocWrapper || ''; // Fallback Platzhalter für spätere Injektion
case 'c':
const langClass = meta ? ` class="language-${meta}"` : '';
@ -217,7 +217,7 @@ class SimonUp {
const escapes = [];
html = html.replace(/\\(.)/g, function(match, char) {
escapes.push(char);
return '';
return `__ESCAPED_CHAR_${escapes.length - 1}__`;
});
html = html.replace(/\/\/(( \s|$))/g, '$1');
@ -280,11 +280,9 @@ class SimonUp {
let regex = new RegExp(rule.symbol + '(.+?)\\\\' + rule.symbol, 'g');
html = html.replace(regex, `<${rule.tag}>$1</${tagSimple}>`);
let resetRegex = new RegExp(rule.symbol + '(.+?)(?=)', 'g');
let resetRegex = new RegExp(rule.symbol + '(.+?)(?=' + rule.symbol + '|$)', 'g');
html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
}
html = html.replace(//g, '');
const alignMap = { 'l': 'left', 'r': 'right', 'c': 'center', 'j': 'justify' };
html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, function(m, dir, content) {
@ -299,7 +297,7 @@ class SimonUp {
html = html.replace(/\^x\[([^\]]+)\]\^x/g, '<span class="footnote-auto" title="$1">[*]</span>');
html = html.replace(/\^(\d+)\[([^\]]+)\]\^x/g, '<sup class="footnote-manual" title="$2">[$1]</sup>');
html = html.replace(//g, function(match, idx) {
html = html.replace(/__ESCAPED_CHAR_(\d+)__/g, function(match, idx) {
return escapes[idx];
});
@ -332,11 +330,12 @@ class SimonUp {
* INTERN: Erzeugt die fertige HTML-Liste des TOC und injiziert sie in den Block
*/
_injectTOC(html) {
if (!html.includes('')) {
const placeholder = '';
if (!html.includes(placeholder) && !html.includes('class="simonup-toc-wrapper"')) {
return html;
}
if (this.headings.length === 0) {
return html.replace('', '');
return html.replace(placeholder, '');
}
let tocListHtml = '<div class="simonup-toc">\n<ul>\n';
@ -361,7 +360,12 @@ class SimonUp {
}
tocListHtml += '</ul>\n</div>';
return html.replace('', tocListHtml);
if (html.includes(placeholder)) {
return html.replace(placeholder, tocListHtml);
} else {
// Falls der Wrapper existiert, hängen wir das Inhaltsverzeichnis hinten an den Wrapper an
return html.replace('</div>', tocListHtml + '\n</div>');
}
}
/**
@ -392,6 +396,8 @@ class SimonUp {
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
if (!element) continue;
let isUlItem = element.startsWith("<ul-item>");
let isOlItem = element.startsWith("<ol-item>");
@ -406,7 +412,25 @@ class SimonUp {
currentListType = type;
listBuffer.push(content);
} else if (element.startsWith("<") && !/^(<a>|<strong>|<em>|<u>|<del>|<mark>|<sup>|<sub>|<span>|<code>|<img>|<h\d)/i.test(element)) {
// Es ist ein fertiges Block-HTML-Element (z.B. <div>, <hr>, <table>, <blockquote>)
flushList();
flushParagraph();
processed.push(element);
} else if (element.trim
} else {
// Freier Text oder Inline-HTML -> Kommt in den Paragraph-Buffer
flushList();
if (element.trim() === "") {
flushParagraph(); // Leere Zeile erzwingt neuen Absatz
} else {
paragraphBuffer.push(element);
}
}
}
// Letzte Reste leeren
flushList();
flushParagraph();
return processed.join("\n");
}
}