From 2096a1fd9af37be0e858d256ff226b2a058f2ec1 Mon Sep 17 00:00:00 2001 From: simonpipe Date: Thu, 9 Jul 2026 18:07:34 +0200 Subject: [PATCH] Update Core.js --- Core.js | 58 ++++++++++++--------------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/Core.js b/Core.js index 15ff84c..5b0d4f7 100644 --- a/Core.js +++ b/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('
'); } else if (trimmed.startsWith('- ')) { - // Freier Listenpunkt (Ungeordnet) result.push(`${this._parseInline(line.replace(/^\s*-\s+/, ''))}`); } else if (/^\d+\.\s+/.test(trimmed)) { - // Freier Listenpunkt (Nummeriert) let cleanLine = line.replace(/^\s*\d+\.\s+/, ''); result.push(`${this._parseInline(cleanLine)}`); } 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 = `
\n`; @@ -150,12 +139,6 @@ class SimonUp { case 't': return this._renderTable(meta, lines); - case '>': - return `
${lines.map(l => this._parseInline(l)).join('
')}
`; - - case '>>': - return `
${lines.map(l => this._parseInline(l)).join('
')}
`; - default: return `
${lines.map(l => this._parseInline(l)).join('
')}
`; } @@ -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 `${fullTitle}${rest}`; }); - // 3b. Nicht im TOC erwünscht (1-# bis 6-#) processHeading(/^([1-6])-#\s*(.*)/g, (level, title, rest) => { return `${title}${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 `${title}${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`); - // 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`); }); - 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 `
${content}
`; }); - // 6. LINKS & MEDIEN html = html.replace(/!\[([^\]]+)\s+w:(\d+)\]\(([^)]+)\)/g, '$1'); html = html.replace(/!\[([^\]]+)\]\(([^)]+)\)/g, '$1'); html = html.replace(/\[([^\]]+)\]\{([^}]+)\}/g, '$1'); html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); - // 7. FUSSNOTEN html = html.replace(/\^x\[([^\]]+)\]\^/g, '[*]'); html = html.replace(/\^(\d+)\[([^\]]+)\]\^/g, '[$1]'); - // 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('<') && !/^(|||||||||||)/i.test(element)) { - // Strukturelles Block-Element (z.B. ,
) 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); }