diff --git a/Core.js b/Core.js
index e80dd1f..a58621d 100644
--- a/Core.js
+++ b/Core.js
@@ -118,19 +118,19 @@ class SimonUp {
switch (type) {
case 'toc':
- let tocWrapper = '';
- if (meta || content.trim()) {
- tocWrapper = '
\n';
- if (meta) {
- tocWrapper += `
${meta}
\n`;
- }
- if (content.trim()) {
- const intro = lines.map(function(l) { return self._parseInline(l); }).join('
');
- tocWrapper += `
${intro}
\n`;
- }
- tocWrapper += '\n
';
- }
- return tocWrapper || ''; // Fallback Platzhalter für spätere Injektion
+ let tocWrapper = '';
+ tocWrapper = '\n';
+ if (meta) {
+ tocWrapper += `
${meta}
\n`;
+ }
+ if (content.trim()) {
+ const intro = lines.map(function(l) { return self._parseInline(l); }).join('
');
+ tocWrapper += `
${intro}
\n`;
+ }
+ // Hier setzen wir den geheimen Platzhalter INSIDE den Wrapper:
+ tocWrapper += '\n';
+ tocWrapper += '
';
+ return tocWrapper;
case 'c':
const langClass = meta ? ` class="language-${meta}"` : '';
@@ -331,16 +331,20 @@ class SimonUp {
*/
_injectTOC(html) {
const placeholder = '';
- if (!html.includes(placeholder) && !html.includes('class="simonup-toc-wrapper"')) {
+
+ // Wenn kein TOC-Block definiert wurde, machen wir nichts
+ if (!html.includes(placeholder)) {
return html;
}
+
+ // Wenn keine Überschriften da sind, entfernen wir einfach den Platzhalter
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) {
@@ -359,13 +363,9 @@ class SimonUp {
tocListHtml += '
\n'.repeat(diffFinal);
}
tocListHtml += '\n
';
-
- 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('', tocListHtml + '\n');
- }
+
+ // Jetzt wird es exakt dort eingefügt, wo es hingehört!
+ return html.replace(placeholder, tocListHtml);
}
/**