Update Core.js
This commit is contained in:
parent
353a32f041
commit
2096a1fd9a
1 changed files with 12 additions and 46 deletions
58
Core.js
58
Core.js
|
|
@ -26,7 +26,6 @@ class SimonUp {
|
|||
|
||||
let html = text;
|
||||
|
||||
// "Before"-Plugins ausführen
|
||||
for (const plugin of this.plugins) {
|
||||
if (plugin.before) html = plugin.before(html);
|
||||
}
|
||||
|
|
@ -34,7 +33,6 @@ class SimonUp {
|
|||
html = this._parseBlocks(html);
|
||||
html = this._injectTOC(html);
|
||||
|
||||
// "After"-Plugins ausführen
|
||||
for (const plugin of this.plugins) {
|
||||
if (plugin.after) html = plugin.after(html);
|
||||
}
|
||||
|
|
@ -56,7 +54,6 @@ class SimonUp {
|
|||
for (let i = 0; i < lines.length; i++) {
|
||||
let line = lines[i];
|
||||
|
||||
// 1. Block-Start erkennen (&typ meta)
|
||||
if (!inBlock && line.startsWith('&') && line.trim().length > 1) {
|
||||
inBlock = true;
|
||||
const fullHeader = line.substring(1).trim();
|
||||
|
|
@ -73,7 +70,6 @@ class SimonUp {
|
|||
continue;
|
||||
}
|
||||
|
||||
// 2. Block-Ende erkennen (einzelnes &)
|
||||
if (inBlock && line.trim() === '&') {
|
||||
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
||||
inBlock = false;
|
||||
|
|
@ -82,30 +78,24 @@ class SimonUp {
|
|||
continue;
|
||||
}
|
||||
|
||||
// 3. Inhalt sammeln oder freie Zeilen verarbeiten
|
||||
if (inBlock) {
|
||||
blockBuffer.push(line);
|
||||
} else {
|
||||
let trimmed = line.trim();
|
||||
|
||||
if (trimmed === '___') {
|
||||
// Horizontale Linie
|
||||
result.push('<hr>');
|
||||
} else if (trimmed.startsWith('- ')) {
|
||||
// Freier Listenpunkt (Ungeordnet)
|
||||
result.push(`<ul-item>${this._parseInline(line.replace(/^\s*-\s+/, ''))}</ul-item>`);
|
||||
} else if (/^\d+\.\s+/.test(trimmed)) {
|
||||
// Freier Listenpunkt (Nummeriert)
|
||||
let cleanLine = line.replace(/^\s*\d+\.\s+/, '');
|
||||
result.push(`<ol-item>${this._parseInline(cleanLine)}</ol-item>`);
|
||||
} else {
|
||||
// Normaler Fließtext
|
||||
result.push(this._parseInline(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Freie Listenpunkte zusammenfassen und Absätze bauen
|
||||
return this._processParagraphsAndLists(result);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +107,6 @@ class SimonUp {
|
|||
|
||||
switch (type) {
|
||||
case 'toc':
|
||||
// Platzhalter für das spätere Injektions-Verfahren hinterlassen
|
||||
let tocWrapper = ``;
|
||||
if (meta || content.trim()) {
|
||||
tocWrapper = `<div class="simonup-toc-wrapper">\n`;
|
||||
|
|
@ -150,12 +139,6 @@ class SimonUp {
|
|||
case 't':
|
||||
return this._renderTable(meta, lines);
|
||||
|
||||
case '>':
|
||||
return `<div style="margin-left: 2em;">${lines.map(l => this._parseInline(l)).join('<br>')}</div>`;
|
||||
|
||||
case '>>':
|
||||
return `<div style="margin-left: 4em;">${lines.map(l => this._parseInline(l)).join('<br>')}</div>`;
|
||||
|
||||
default:
|
||||
return `<div class="block-${type}">${lines.map(l => this._parseInline(l)).join('<br>')}</div>`;
|
||||
}
|
||||
|
|
@ -169,7 +152,6 @@ class SimonUp {
|
|||
let currentCells = [];
|
||||
let cellBuffer = [];
|
||||
|
||||
// Parsing-Logik für Multi-line-Zellen via Pipe (|)
|
||||
for (let line of lines) {
|
||||
let parts = line.split('|');
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
|
|
@ -206,17 +188,14 @@ class SimonUp {
|
|||
if (!text) return '';
|
||||
let html = text;
|
||||
|
||||
// 1. ESCAPE: Steuerzeichen sichern (Schutz vor doppelter Evaluierung)
|
||||
const escapes = [];
|
||||
html = html.replace(/\\(.)/g, (match, char) => {
|
||||
escapes.push(char);
|
||||
return ``;
|
||||
});
|
||||
|
||||
// 2. UNIVERSAL-RESET: Verarbeitet den "//"-Reset im Satz
|
||||
html = html.replace(/\/\/(\s|$)/g, '$1');
|
||||
|
||||
// 3. ÜBERSCHRIFTEN (V1.2 konform: Startet mit X#, schließt optional mit /# oder Zeilenende)
|
||||
const processHeading = (pattern, callback) => {
|
||||
let match;
|
||||
while ((match = pattern.exec(html)) !== null) {
|
||||
|
|
@ -224,7 +203,6 @@ class SimonUp {
|
|||
const level = parseInt(match[1]);
|
||||
const titleAndRest = match[2];
|
||||
|
||||
// Schließzeichen /# suchen, sonst bis Zeilenende parsen
|
||||
let title = titleAndRest;
|
||||
let rest = "";
|
||||
const closeIdx = titleAndRest.indexOf('/#');
|
||||
|
|
@ -238,7 +216,6 @@ class SimonUp {
|
|||
}
|
||||
};
|
||||
|
||||
// 3a. Automatische Nummerierung (1x# bis 6x#)
|
||||
processHeading(/^([1-6])x#\s*(.*)/g, (level, title, rest) => {
|
||||
const numStr = this._getAutoNumber(level);
|
||||
const fullTitle = `${numStr} ${title}`;
|
||||
|
|
@ -247,58 +224,50 @@ class SimonUp {
|
|||
return `<h${level} id="${id}">${fullTitle}</h${level}>${rest}`;
|
||||
});
|
||||
|
||||
// 3b. Nicht im TOC erwünscht (1-# bis 6-#)
|
||||
processHeading(/^([1-6])-#\s*(.*)/g, (level, title, rest) => {
|
||||
return `<h${level}>${title}</h${level}>${rest}`;
|
||||
});
|
||||
|
||||
// 3c. Standard-Überschrift (1# bis 6#)
|
||||
processHeading(/^([1-6])#\s*(.*)/g, (level, title, rest) => {
|
||||
const id = this._slugify(title);
|
||||
this.headings.push({ level, text: title, id });
|
||||
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
||||
});
|
||||
|
||||
// 4. INLINE SCHLIESS-LOGIK (V1.2: ZeichenText/Zeichen)
|
||||
const inlineRules = [
|
||||
{ tag: 'strong', symbol: '\\*\\*' }, // Fett (**Text/**)
|
||||
{ tag: 'span style="font-weight: 500;"', symbol: '\\*' }, // Medium (*Text/*)
|
||||
{ tag: 'em', symbol: '%' }, // Kursiv (%Text/%)
|
||||
{ tag: 'u', symbol: '_' }, // Unterstrichen (_Text/_)
|
||||
{ tag: 'del', symbol: '~' }, // Durchgestrichen (~Text/~)
|
||||
{ tag: 'mark', symbol: '=' }, // Highlight (=Text/=)
|
||||
{ tag: 'sup', symbol: '\\^' }, // Hochgestellt (^Text/^)
|
||||
{ tag: 'sub', symbol: '°' }, // Tiefgestellt (°Text/°)
|
||||
{ tag: 'code', symbol: '`' } // Inline-Code (`Text/`)
|
||||
{ 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: '`' }
|
||||
];
|
||||
|
||||
inlineRules.forEach(rule => {
|
||||
// Regulärer Match: Symbol -> Text -> /Symbol
|
||||
let regex = new RegExp(`${rule.symbol}(.+?)\/${rule.symbol}`, 'g');
|
||||
html = html.replace(regex, `<${rule.tag}>$1</${rule.tag.split(' ')[0]}>`);
|
||||
|
||||
// Fallback für Universal-Reset: Offenes Symbol bis zum let resetRegex = new RegExp(`${rule.symbol}(.+?)(?=)`, 'g');
|
||||
let resetRegex = new RegExp(`${rule.symbol}(.+?)(?=)`, 'g');
|
||||
html = html.replace(resetRegex, `<${rule.tag}>$1</${rule.tag.split(' ')[0]}>`);
|
||||
});
|
||||
html = html.replace(//g, ''); // Aufgeräumte Reset-Tags
|
||||
html = html.replace(//g, '');
|
||||
|
||||
// 5. AUSRICHTUNG IM FLUSS (>c Text />)
|
||||
const alignMap = { l: 'left', r: 'right', c: 'center', j: 'justify' };
|
||||
html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, (m, dir, content) => {
|
||||
return `<div style="text-align: ${alignMap[dir]};">${content}</div>`;
|
||||
});
|
||||
|
||||
// 6. LINKS & MEDIEN
|
||||
html = html.replace(/!\[([^\]]+)\s+w:(\d+)\]\(([^)]+)\)/g, '<img src="$3" alt="$1" style="width: $2px; height: auto;">');
|
||||
html = html.replace(/!\[([^\]]+)\]\(([^)]+)\)/g, '<img src="$2" alt="$1">');
|
||||
html = html.replace(/\[([^\]]+)\]\{([^}]+)\}/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
|
||||
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
||||
|
||||
// 7. FUSSNOTEN
|
||||
html = html.replace(/\^x\[([^\]]+)\]\^/g, '<span class="footnote-auto" title="$1">[*]</span>');
|
||||
html = html.replace(/\^(\d+)\[([^\]]+)\]\^/g, '<sup class="footnote-manual" title="$2">[$1]</sup>');
|
||||
|
||||
// 8. ESCAPES wiederherstellen
|
||||
html = html.replace(//g, (match, idx) => escapes[idx]);
|
||||
|
||||
return html;
|
||||
|
|
@ -359,7 +328,7 @@ class SimonUp {
|
|||
let processed = [];
|
||||
let paragraphBuffer = [];
|
||||
let listBuffer = [];
|
||||
let currentListType = null; // 'ul' oder 'ol'
|
||||
let currentListType = null;
|
||||
|
||||
const flushList = () => {
|
||||
if (listBuffer.length > 0) {
|
||||
|
|
@ -391,16 +360,13 @@ 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)) {
|
||||
// Strukturelles Block-Element (z.B. <table>, <blockquote>)
|
||||
flushList();
|
||||
flushParagraph();
|
||||
processed.push(element);
|
||||
} else if (element.trim() === '') {
|
||||
// Leerzeile bricht Listen und Absätze auf
|
||||
flushList();
|
||||
flushParagraph();
|
||||
} else {
|
||||
// Fließtext mündet im Absatz-Buffer
|
||||
flushList();
|
||||
paragraphBuffer.push(element);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue