Update Core.js
This commit is contained in:
parent
90d5e24b1a
commit
248f54634a
1 changed files with 23 additions and 23 deletions
46
Core.js
46
Core.js
|
|
@ -118,19 +118,19 @@ class SimonUp {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'toc':
|
case 'toc':
|
||||||
let tocWrapper = '';
|
let tocWrapper = '';
|
||||||
if (meta || content.trim()) {
|
tocWrapper = '<div class="simonup-toc-wrapper">\n';
|
||||||
tocWrapper = '<div class="simonup-toc-wrapper">\n';
|
if (meta) {
|
||||||
if (meta) {
|
tocWrapper += `<h2>${meta}</h2>\n`;
|
||||||
tocWrapper += `<h2>${meta}</h2>\n`;
|
}
|
||||||
}
|
if (content.trim()) {
|
||||||
if (content.trim()) {
|
const intro = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
|
||||||
const intro = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
|
tocWrapper += `<p class="toc-intro">${intro}</p>\n`;
|
||||||
tocWrapper += `<p class="toc-intro">${intro}</p>\n`;
|
}
|
||||||
}
|
// Hier setzen wir den geheimen Platzhalter INSIDE den Wrapper:
|
||||||
tocWrapper += '\n</div>';
|
tocWrapper += '\n';
|
||||||
}
|
tocWrapper += '</div>';
|
||||||
return tocWrapper || ''; // Fallback Platzhalter für spätere Injektion
|
return tocWrapper;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
const langClass = meta ? ` class="language-${meta}"` : '';
|
const langClass = meta ? ` class="language-${meta}"` : '';
|
||||||
|
|
@ -331,16 +331,20 @@ class SimonUp {
|
||||||
*/
|
*/
|
||||||
_injectTOC(html) {
|
_injectTOC(html) {
|
||||||
const placeholder = '';
|
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;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn keine Überschriften da sind, entfernen wir einfach den Platzhalter
|
||||||
if (this.headings.length === 0) {
|
if (this.headings.length === 0) {
|
||||||
return html.replace(placeholder, '');
|
return html.replace(placeholder, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
let tocListHtml = '<div class="simonup-toc">\n<ul>\n';
|
let tocListHtml = '<div class="simonup-toc">\n<ul>\n';
|
||||||
let currentLevel = 1;
|
let currentLevel = 1;
|
||||||
|
|
||||||
for (let i = 0; i < this.headings.length; i++) {
|
for (let i = 0; i < this.headings.length; i++) {
|
||||||
let heading = this.headings[i];
|
let heading = this.headings[i];
|
||||||
if (heading.level > currentLevel) {
|
if (heading.level > currentLevel) {
|
||||||
|
|
@ -359,13 +363,9 @@ class SimonUp {
|
||||||
tocListHtml += '</ul>\n'.repeat(diffFinal);
|
tocListHtml += '</ul>\n'.repeat(diffFinal);
|
||||||
}
|
}
|
||||||
tocListHtml += '</ul>\n</div>';
|
tocListHtml += '</ul>\n</div>';
|
||||||
|
|
||||||
if (html.includes(placeholder)) {
|
// Jetzt wird es exakt dort eingefügt, wo es hingehört!
|
||||||
return html.replace(placeholder, tocListHtml);
|
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>');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue