Update Core.js
This commit is contained in:
parent
248f54634a
commit
dff3723655
1 changed files with 39 additions and 43 deletions
62
Core.js
62
Core.js
|
|
@ -118,8 +118,7 @@ class SimonUp {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'toc':
|
case 'toc':
|
||||||
let tocWrapper = '';
|
let 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`;
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +126,7 @@ class SimonUp {
|
||||||
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:
|
// Eindeutiges Token exakt im Container platzieren
|
||||||
tocWrapper += '\n';
|
tocWrapper += '\n';
|
||||||
tocWrapper += '</div>';
|
tocWrapper += '</div>';
|
||||||
return tocWrapper;
|
return tocWrapper;
|
||||||
|
|
@ -222,6 +221,31 @@ class SimonUp {
|
||||||
|
|
||||||
html = html.replace(/\/\/(( \s|$))/g, '$1');
|
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;
|
let self = this;
|
||||||
const processHeading = function(pattern, callback) {
|
const processHeading = function(pattern, callback) {
|
||||||
let match;
|
let match;
|
||||||
|
|
@ -261,29 +285,7 @@ class SimonUp {
|
||||||
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const inlineRules = [
|
// 3. RESTLICHE STRUKTUREN (Ausrichtungen, Links, Medien)
|
||||||
{ 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}>`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const alignMap = { 'l': 'left', 'r': 'right', 'c': 'center', 'j': 'justify' };
|
const alignMap = { 'l': 'left', 'r': 'right', 'c': 'center', 'j': 'justify' };
|
||||||
html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, function(m, dir, content) {
|
html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, function(m, dir, content) {
|
||||||
return `<div style="text-align: ${alignMap[dir]};">${content}</div>`;
|
return `<div style="text-align: ${alignMap[dir]};">${content}</div>`;
|
||||||
|
|
@ -332,12 +334,10 @@ class SimonUp {
|
||||||
_injectTOC(html) {
|
_injectTOC(html) {
|
||||||
const placeholder = '';
|
const placeholder = '';
|
||||||
|
|
||||||
// Wenn kein TOC-Block definiert wurde, machen wir nichts
|
|
||||||
if (!html.includes(placeholder)) {
|
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, '');
|
||||||
}
|
}
|
||||||
|
|
@ -364,7 +364,6 @@ class SimonUp {
|
||||||
}
|
}
|
||||||
tocListHtml += '</ul>\n</div>';
|
tocListHtml += '</ul>\n</div>';
|
||||||
|
|
||||||
// Jetzt wird es exakt dort eingefügt, wo es hingehört!
|
|
||||||
return html.replace(placeholder, tocListHtml);
|
return html.replace(placeholder, tocListHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,22 +411,19 @@ class SimonUp {
|
||||||
currentListType = type;
|
currentListType = type;
|
||||||
listBuffer.push(content);
|
listBuffer.push(content);
|
||||||
} else if (element.startsWith("<") && !/^(<a>|<strong>|<em>|<u>|<del>|<mark>|<sup>|<sub>|<span>|<code>|<img>|<h\d)/i.test(element)) {
|
} 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();
|
flushList();
|
||||||
flushParagraph();
|
flushParagraph();
|
||||||
processed.push(element);
|
processed.push(element);
|
||||||
} else {
|
} else {
|
||||||
// Freier Text oder Inline-HTML -> Kommt in den Paragraph-Buffer
|
|
||||||
flushList();
|
flushList();
|
||||||
if (element.trim() === "") {
|
if (element.trim() === "") {
|
||||||
flushParagraph(); // Leere Zeile erzwingt neuen Absatz
|
flushParagraph();
|
||||||
} else {
|
} else {
|
||||||
paragraphBuffer.push(element);
|
paragraphBuffer.push(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Letzte Reste leeren
|
|
||||||
flushList();
|
flushList();
|
||||||
flushParagraph();
|
flushParagraph();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue