Update Core.js
This commit is contained in:
parent
8682d6af9d
commit
b0ba56ef70
1 changed files with 47 additions and 27 deletions
74
Core.js
74
Core.js
|
|
@ -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.
|
* Eine moderne, fluss- und blockorientierte Auszeichnungssprache.
|
||||||
*/
|
*/
|
||||||
class SimonUp {
|
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);
|
html = this._parseBlocks(html);
|
||||||
|
|
||||||
// Phase 2: Das Inhaltsverzeichnis nachträglich in die vorbereitete Box einsetzen
|
// Phase 2: Das Inhaltsverzeichnis nachträglich in die vorbereitete Box einsetzen
|
||||||
|
|
@ -82,7 +82,7 @@ class SimonUp {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block-Ende erkennen mit /& (Spezifikation V1.2b)
|
// Block-Ende erkennen mit /&
|
||||||
if (inBlock && line.trim().replace(/\u00A0/g, ' ') === '/&') {
|
if (inBlock && line.trim().replace(/\u00A0/g, ' ') === '/&') {
|
||||||
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
||||||
inBlock = false;
|
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);
|
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) {
|
_renderTable(meta, lines) {
|
||||||
let tableHtml = '<table>\n';
|
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) {
|
_parseInline(text) {
|
||||||
if (!text) return '';
|
if (!text) return '';
|
||||||
|
|
@ -225,9 +230,7 @@ class SimonUp {
|
||||||
return `__ESCAPED_CHAR_${escapes.length - 1}__`;
|
return `__ESCAPED_CHAR_${escapes.length - 1}__`;
|
||||||
});
|
});
|
||||||
|
|
||||||
html = html.replace(/\/\/(( \s|$))/g, '$1');
|
// 1. Überschriften ERST parsen (bevor HTML-Tags im Fluss entstehen)
|
||||||
|
|
||||||
// Überschriften-Parsing via .replace() zur Verhinderung von Index-Shifts
|
|
||||||
html = html.replace(/^([1-6])x#\s*(.*)/gm, (match, level, titleAndRest) => {
|
html = html.replace(/^([1-6])x#\s*(.*)/gm, (match, level, titleAndRest) => {
|
||||||
let { title, rest } = this._extractHeadingRest(titleAndRest);
|
let { title, rest } = this._extractHeadingRest(titleAndRest);
|
||||||
const numStr = this._getAutoNumber(parseInt(level));
|
const numStr = this._getAutoNumber(parseInt(level));
|
||||||
|
|
@ -249,15 +252,40 @@ class SimonUp {
|
||||||
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Kritische Doppel-Sterne (fett)
|
// Medien & Links verarbeiten
|
||||||
html = html.replace(/\*\*(.+?)\\\*\*/g, '<strong>$1</strong>');
|
html = html.replace(/!\[([^\]]+)\s+w:(\d+)\]\(([^)]+)\)/g, '<img src="$3" alt="$1" style="width: $2px; height: auto;">');
|
||||||
html = html.replace(/\*\*(.+?)(?=\*\*|$)/g, '<strong>$1</strong>');
|
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)
|
// Hilfsfunktion: Führt Ersetzungen nur AUSSERHALB von HTML-Tags <...> aus
|
||||||
html = html.replace(/\*(.+?)\\\*/g, '<span style="font-weight: 500;">$1</span>');
|
const replaceOutsideTags = (regex, replacement) => {
|
||||||
html = html.replace(/\*(.+?)(?=\*|$)/g, '<span style="font-weight: 500;">$1</span>');
|
const masterRegex = new RegExp(/(<[^>]+>)/g.source + '|' + regex.source, 'g');
|
||||||
|
html = html.replace(masterRegex, (match, p1) => {
|
||||||
|
if (p1) return p1; // HTML-Tags überspringen
|
||||||
|
|
||||||
// Standard Text-Inline-Rules
|
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;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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 = [
|
const inlineRules = [
|
||||||
{ tag: 'em', symbol: '%' },
|
{ tag: 'em', symbol: '%' },
|
||||||
{ tag: 'u', symbol: '_' },
|
{ tag: 'u', symbol: '_' },
|
||||||
|
|
@ -272,24 +300,16 @@ class SimonUp {
|
||||||
let rule = inlineRules[k];
|
let rule = inlineRules[k];
|
||||||
let tagSimple = rule.tag.split(' ')[0];
|
let tagSimple = rule.tag.split(' ')[0];
|
||||||
|
|
||||||
let regex = new RegExp(rule.symbol + '(.+?)\\\\' + rule.symbol, 'g');
|
// Unterstützt %text/% sowie das Fallback %text am Zeilenende
|
||||||
html = html.replace(regex, `<${rule.tag}>$1</${tagSimple}>`);
|
replaceOutsideTags(new RegExp(rule.symbol + '(.+?)(?:\\/' + rule.symbol + '|\\/|' + rule.symbol + '|$)'), `<${rule.tag}>$1</${tagSimple}>`);
|
||||||
|
|
||||||
let resetRegex = new RegExp(rule.symbol + '(.+?)(?=' + rule.symbol + '|$)', 'g');
|
|
||||||
html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ausrichtungen, Links, Medien
|
// Ausrichtungen & Fußnoten
|
||||||
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>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
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(/\^x\[([^\]]+)\]\^x/g, '<span class="footnote-auto" title="$1">[*]</span>');
|
||||||
html = html.replace(/\^(\d+)\[([^\]]+)\]\^x/g, '<sup class="footnote-manual" title="$2">[$1]</sup>');
|
html = html.replace(/\^(\d+)\[([^\]]+)\]\^x/g, '<sup class="footnote-manual" title="$2">[$1]</sup>');
|
||||||
|
|
||||||
|
|
@ -418,7 +438,7 @@ 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[1-6])/i.test(element)) {
|
||||||
flushList();
|
flushList();
|
||||||
flushParagraph();
|
flushParagraph();
|
||||||
processed.push(element);
|
processed.push(element);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue