Update Core.js
This commit is contained in:
parent
248f54634a
commit
dff3723655
1 changed files with 39 additions and 43 deletions
82
Core.js
82
Core.js
|
|
@ -118,19 +118,18 @@ class SimonUp {
|
|||
|
||||
switch (type) {
|
||||
case 'toc':
|
||||
let tocWrapper = '';
|
||||
tocWrapper = '<div class="simonup-toc-wrapper">\n';
|
||||
if (meta) {
|
||||
tocWrapper += `<h2>${meta}</h2>\n`;
|
||||
}
|
||||
if (content.trim()) {
|
||||
const intro = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
|
||||
tocWrapper += `<p class="toc-intro">${intro}</p>\n`;
|
||||
}
|
||||
// Hier setzen wir den geheimen Platzhalter INSIDE den Wrapper:
|
||||
tocWrapper += '\n';
|
||||
tocWrapper += '</div>';
|
||||
return tocWrapper;
|
||||
let tocWrapper = '<div class="simonup-toc-wrapper">\n';
|
||||
if (meta) {
|
||||
tocWrapper += `<h2>${meta}</h2>\n`;
|
||||
}
|
||||
if (content.trim()) {
|
||||
const intro = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
|
||||
tocWrapper += `<p class="toc-intro">${intro}</p>\n`;
|
||||
}
|
||||
// Eindeutiges Token exakt im Container platzieren
|
||||
tocWrapper += '\n';
|
||||
tocWrapper += '</div>';
|
||||
return tocWrapper;
|
||||
|
||||
case 'c':
|
||||
const langClass = meta ? ` class="language-${meta}"` : '';
|
||||
|
|
@ -222,6 +221,31 @@ class SimonUp {
|
|||
|
||||
html = html.replace(/\/\/(( \s|$))/g, '$1');
|
||||
|
||||
// 1. ZUERST: Standard Text-Inline-Rules parsen
|
||||
const inlineRules = [
|
||||
{ tag: 'strong', symbol: '\\*\\*' },
|
||||
{ tag: 'span style="font-weight: 500;"', symbol: '\\*' },
|
||||
{ tag: 'em', symbol: '%' },
|
||||
{ tag: 'u', symbol: '_' },
|
||||
{ tag: 'del', symbol: '~' },
|
||||
{ tag: 'mark', symbol: '=' },
|
||||
{ tag: 'sup', symbol: '\\^' },
|
||||
{ tag: 'sub', symbol: '°' },
|
||||
{ tag: 'code', symbol: '`' }
|
||||
];
|
||||
|
||||
for (let k = 0; k < inlineRules.length; k++) {
|
||||
let rule = inlineRules[k];
|
||||
let tagSimple = rule.tag.split(' ')[0];
|
||||
|
||||
let regex = new RegExp(rule.symbol + '(.+?)\\\\' + rule.symbol, 'g');
|
||||
html = html.replace(regex, `<${rule.tag}>$1</${tagSimple}>`);
|
||||
|
||||
let resetRegex = new RegExp(rule.symbol + '(.+?)(?=' + rule.symbol + '|$)', 'g');
|
||||
html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
|
||||
}
|
||||
|
||||
// 2. DANACH: Überschriften generieren (schützt generierte id="" Attribute vor den Regeln oben)
|
||||
let self = this;
|
||||
const processHeading = function(pattern, callback) {
|
||||
let match;
|
||||
|
|
@ -261,29 +285,7 @@ class SimonUp {
|
|||
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
||||
});
|
||||
|
||||
const inlineRules = [
|
||||
{ tag: 'strong', symbol: '\\*\\*' },
|
||||
{ tag: 'span style="font-weight: 500;"', symbol: '\\*' },
|
||||
{ tag: 'em', symbol: '%' },
|
||||
{ tag: 'u', symbol: '_' },
|
||||
{ tag: 'del', symbol: '~' },
|
||||
{ tag: 'mark', symbol: '=' },
|
||||
{ tag: 'sup', symbol: '\\^' },
|
||||
{ tag: 'sub', symbol: '°' },
|
||||
{ tag: 'code', symbol: '`' }
|
||||
];
|
||||
|
||||
for (let k = 0; k < inlineRules.length; k++) {
|
||||
let rule = inlineRules[k];
|
||||
let tagSimple = rule.tag.split(' ')[0];
|
||||
|
||||
let regex = new RegExp(rule.symbol + '(.+?)\\\\' + rule.symbol, 'g');
|
||||
html = html.replace(regex, `<${rule.tag}>$1</${tagSimple}>`);
|
||||
|
||||
let resetRegex = new RegExp(rule.symbol + '(.+?)(?=' + rule.symbol + '|$)', 'g');
|
||||
html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
|
||||
}
|
||||
|
||||
// 3. RESTLICHE STRUKTUREN (Ausrichtungen, Links, Medien)
|
||||
const alignMap = { 'l': 'left', 'r': 'right', 'c': 'center', 'j': 'justify' };
|
||||
html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, function(m, dir, content) {
|
||||
return `<div style="text-align: ${alignMap[dir]};">${content}</div>`;
|
||||
|
|
@ -332,12 +334,10 @@ class SimonUp {
|
|||
_injectTOC(html) {
|
||||
const placeholder = '';
|
||||
|
||||
// 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, '');
|
||||
}
|
||||
|
|
@ -364,7 +364,6 @@ class SimonUp {
|
|||
}
|
||||
tocListHtml += '</ul>\n</div>';
|
||||
|
||||
// Jetzt wird es exakt dort eingefügt, wo es hingehört!
|
||||
return html.replace(placeholder, tocListHtml);
|
||||
}
|
||||
|
||||
|
|
@ -412,22 +411,19 @@ class SimonUp {
|
|||
currentListType = type;
|
||||
listBuffer.push(content);
|
||||
} else if (element.startsWith("<") && !/^(<a>|<strong>|<em>|<u>|<del>|<mark>|<sup>|<sub>|<span>|<code>|<img>|<h\d)/i.test(element)) {
|
||||
// Es ist ein fertiges Block-HTML-Element (z.B. <div>, <hr>, <table>, <blockquote>)
|
||||
flushList();
|
||||
flushParagraph();
|
||||
processed.push(element);
|
||||
} else {
|
||||
// Freier Text oder Inline-HTML -> Kommt in den Paragraph-Buffer
|
||||
flushList();
|
||||
if (element.trim() === "") {
|
||||
flushParagraph(); // Leere Zeile erzwingt neuen Absatz
|
||||
flushParagraph();
|
||||
} else {
|
||||
paragraphBuffer.push(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Letzte Reste leeren
|
||||
flushList();
|
||||
flushParagraph();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue