Update Core.js

This commit is contained in:
simonpipe 2026-07-09 23:21:48 +02:00
parent f444ae5735
commit 0428c0d37f

23
Core.js
View file

@ -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('<br>');
tocWrapper += `<p class="toc-intro">${intro}</p>\n`;
}
// HIER IST JETZT DER ECHTE PLATZHALTER:
tocWrapper += '\n';
tocWrapper += '</div>';
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 `<h${level} id="${id}">${fullTitle}</h${level}>${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 = '<div class="simonup-toc">\n<ul>\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 += `<li><a href="#${heading.id}">${heading.text}</a></li>\n`;
}
if (currentLevel > 1) {
let diffFinal = currentLevel - 1;
tocListHtml += '</ul>\n'.repeat(diffFinal);
}
tocListHtml += '</ul>\n</div>';
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("<ul-item>");
let isOlItem = element.startsWith("<ol-item>");
@ -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();
}