diff --git a/Core.js b/Core.js
index f81bcd1..edcf6eb 100644
--- a/Core.js
+++ b/Core.js
@@ -34,7 +34,10 @@ class SimonUp {
}
}
+ // Phase 1: Blöcke und Inline-Strukturen parsen (sammelt auch alle Überschriften)
html = this._parseBlocks(html);
+
+ // Phase 2: Das Inhaltsverzeichnis nachträglich in die vorbereitete Box einsetzen
html = this._injectTOC(html);
if (this.plugins && this.plugins.length > 0) {
@@ -126,6 +129,7 @@ class SimonUp {
const intro = lines.map(function(l) { return self._parseInline(l); }).join('
');
tocWrapper += `
${intro}
\n`;
}
+ // HIER IST JETZT DER ECHTE PLATZHALTER:
tocWrapper += '\n';
tocWrapper += '';
return tocWrapper;
@@ -270,7 +274,7 @@ class SimonUp {
const numStr = self._getAutoNumber(level);
const fullTitle = `${numStr} ${title}`;
const id = self._slugify(fullTitle);
- self.headings.push({ level: level, text: fullTitle, id: id });
+ self.headings.push({ level: level, text: title, id: id }); // Speichert nur den puren Titel ohne Nummer für das TOC Link-Markup
return `${fullTitle}${rest}`;
});
@@ -331,19 +335,20 @@ class SimonUp {
* INTERN: Erzeugt die fertige HTML-Liste des TOC und injiziert sie in den Block
*/
_injectTOC(html) {
+ // HIER STEHT JETZT DEFINITIV DAS RECHTE TOKEN:
const placeholder = '';
-
+
if (!html.includes(placeholder)) {
return html;
}
-
+
if (this.headings.length === 0) {
return html.replace(placeholder, '');
}
-
+
let tocListHtml = '\n
\n';
let currentLevel = 1;
-
+
for (let i = 0; i < this.headings.length; i++) {
let heading = this.headings[i];
if (heading.level > currentLevel) {
@@ -356,13 +361,13 @@ class SimonUp {
currentLevel = heading.level;
tocListHtml += `- ${heading.text}
\n`;
}
-
+
if (currentLevel > 1) {
let diffFinal = currentLevel - 1;
tocListHtml += '
\n'.repeat(diffFinal);
}
tocListHtml += '\n
';
-
+
return html.replace(placeholder, tocListHtml);
}
@@ -395,7 +400,7 @@ class SimonUp {
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
if (!element) continue;
-
+
let isUlItem = element.startsWith("");
let isOlItem = element.startsWith("");
@@ -403,7 +408,7 @@ class SimonUp {
flushParagraph();
let type = isUlItem ? "ul" : "ol";
let content = isUlItem ? element.replace(/<\/?ul-item>/g, "") : element.replace(/<\/?ol-item>/g, "");
-
+
if (currentListType && currentListType !== type) {
flushList();
}