Update Core.js

This commit is contained in:
simonpipe 2026-07-10 11:32:19 +02:00
parent 8682d6af9d
commit b0ba56ef70

74
Core.js
View file

@ -1,5 +1,5 @@
/**
* SimonUp Core Compiler (Core.js) - Version 1.2b.001
* SimonUp Core Compiler (Core.js) - Version 1.2.3
* Eine moderne, fluss- und blockorientierte Auszeichnungssprache.
*/
class SimonUp {
@ -34,7 +34,7 @@ class SimonUp {
}
}
// Phase 1: Blöcke und Inline-Strukturen parsen (sammelt alle Überschriften)
// Phase 1: Blöcke und Inline-Strukturen parsen
html = this._parseBlocks(html);
// Phase 2: Das Inhaltsverzeichnis nachträglich in die vorbereitete Box einsetzen
@ -82,7 +82,7 @@ class SimonUp {
continue;
}
// Block-Ende erkennen mit /& (Spezifikation V1.2b)
// Block-Ende erkennen mit /&
if (inBlock && line.trim().replace(/\u00A0/g, ' ') === '/&') {
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
inBlock = false;
@ -111,6 +111,11 @@ class SimonUp {
}
}
// Automatischer Schutz: Falls am Dateiende ein Block nicht geschlossen wurde
if (inBlock && blockBuffer.length > 0) {
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
}
return this._processParagraphsAndLists(result);
}
@ -168,7 +173,7 @@ class SimonUp {
}
/**
* INTERN: Robustes Rendern von Multi-line-Tabellen und Galerien (V1.2b)
* INTERN: Robustes Rendern von Multi-line-Tabellen und Galerien
*/
_renderTable(meta, lines) {
let tableHtml = '<table>\n';
@ -213,7 +218,7 @@ class SimonUp {
}
/**
* INTERN: Verarbeitet Fluss-Formatierungen (Inline)
* INTERN: Verarbeitet Fluss-Formatierungen (Inline) ohne HTML-Zerstörung
*/
_parseInline(text) {
if (!text) return '';
@ -225,9 +230,7 @@ class SimonUp {
return `__ESCAPED_CHAR_${escapes.length - 1}__`;
});
html = html.replace(/\/\/(( \s|$))/g, '$1');
// Überschriften-Parsing via .replace() zur Verhinderung von Index-Shifts
// 1. Überschriften ERST parsen (bevor HTML-Tags im Fluss entstehen)
html = html.replace(/^([1-6])x#\s*(.*)/gm, (match, level, titleAndRest) => {
let { title, rest } = this._extractHeadingRest(titleAndRest);
const numStr = this._getAutoNumber(parseInt(level));
@ -249,15 +252,40 @@ class SimonUp {
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
});
// Kritische Doppel-Sterne (fett)
html = html.replace(/\*\*(.+?)\\\*\*/g, '<strong>$1</strong>');
html = html.replace(/\*\*(.+?)(?=\*\*|$)/g, '<strong>$1</strong>');
// Medien & Links verarbeiten
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>');
// Einzelne Sternchen (medium)
html = html.replace(/\*(.+?)\\\*/g, '<span style="font-weight: 500;">$1</span>');
html = html.replace(/\*(.+?)(?=\*|$)/g, '<span style="font-weight: 500;">$1</span>');
// Hilfsfunktion: Führt Ersetzungen nur AUSSERHALB von HTML-Tags <...> aus
const replaceOutsideTags = (regex, replacement) => {
const masterRegex = new RegExp(/(<[^>]+>)/g.source + '|' + regex.source, 'g');
html = html.replace(masterRegex, (match, p1) => {
if (p1) return p1; // HTML-Tags überspringen
const innerMatch = regex.exec(match);
if (innerMatch) {
if (typeof replacement === 'function') {
return replacement(...innerMatch);
}
let res = replacement;
for (let idx = 1; idx < innerMatch.length; idx++) {
res = res.replace(new RegExp('\\$' + idx, 'g'), innerMatch[idx]);
}
return res;
}
return match;
});
};
// Standard Text-Inline-Rules
// 2. Formatierung für FETT (**text/** oder **text/)
replaceOutsideTags(/\*\*(.+?)(?:\/\*\*|\/|\*\*|$)/, '<strong>$1</strong>');
// 3. Formatierung für MEDIUM (*text/* oder *text/)
replaceOutsideTags(/\*(.+?)(?:\/\*|\/|\*|$)/, '<span style="font-weight: 500;">$1</span>');
// 4. Standard Text-Inline-Rules via Symbol-Paar/Slash-Abschluss
const inlineRules = [
{ tag: 'em', symbol: '%' },
{ tag: 'u', symbol: '_' },
@ -272,24 +300,16 @@ class SimonUp {
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}>`);
// Unterstützt %text/% sowie das Fallback %text am Zeilenende
replaceOutsideTags(new RegExp(rule.symbol + '(.+?)(?:\\/' + rule.symbol + '|\\/|' + rule.symbol + '|$)'), `<${rule.tag}>$1</${tagSimple}>`);
}
// Ausrichtungen, Links, Medien
// Ausrichtungen & Fußnoten
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>`;
});
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>');
html = html.replace(/\^x\[([^\]]+)\]\^x/g, '<span class="footnote-auto" title="$1">[*]</span>');
html = html.replace(/\^(\d+)\[([^\]]+)\]\^x/g, '<sup class="footnote-manual" title="$2">[$1]</sup>');
@ -418,7 +438,7 @@ 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)) {
} else if (element.startsWith("<") && !/^(<a>|<strong>|<em>|<u>|<del>|<mark>|<sup>|<sub>|<span>|<code>|<img>|<h[1-6])/i.test(element)) {
flushList();
flushParagraph();
processed.push(element);