diff --git a/Core.js b/Core.js index e50ad96..e80dd1f 100644 --- a/Core.js +++ b/Core.js @@ -130,7 +130,7 @@ class SimonUp { } tocWrapper += '\n'; } - 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, '[*]'); html = html.replace(/\^(\d+)\[([^\]]+)\]\^x/g, '[$1]'); - 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 = '
|
|,
, , )
flushList();
flushParagraph();
processed.push(element);
- } else if (element.trim
\ No newline at end of file
+ } 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");
+ }
+}
\ No newline at end of file