Update Core.js
This commit is contained in:
parent
be8a5821ca
commit
2d4c2580ac
1 changed files with 81 additions and 81 deletions
152
Core.js
152
Core.js
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* SimonUp Core Compiler (Core.js) - Version 1.2.1
|
* SimonUp Core Compiler (Core.js) - Version 1.2b.001
|
||||||
* Eine moderne, fluss- und blockorientierte Auszeichnungssprache.
|
* Eine moderne, fluss- und blockorientierte Auszeichnungssprache.
|
||||||
*/
|
*/
|
||||||
class SimonUp {
|
class SimonUp {
|
||||||
|
|
@ -65,6 +65,7 @@ class SimonUp {
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
let line = lines[i];
|
let line = lines[i];
|
||||||
|
|
||||||
|
// Block-Start erkennen (&typ meta)
|
||||||
if (!inBlock && line.startsWith('&') && line.trim().length > 1) {
|
if (!inBlock && line.startsWith('&') && line.trim().length > 1) {
|
||||||
inBlock = true;
|
inBlock = true;
|
||||||
const fullHeader = line.substring(1).trim();
|
const fullHeader = line.substring(1).trim();
|
||||||
|
|
@ -81,7 +82,8 @@ class SimonUp {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBlock && line.trim().replace(/\u00A0/g, ' ') === '&') {
|
// Block-Ende erkennen mit /& (Spezifikation V1.2b)
|
||||||
|
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;
|
||||||
blockType = null;
|
blockType = null;
|
||||||
|
|
@ -166,50 +168,52 @@ class SimonUp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERN: Hilfsfunktion zum Rendern von Multi-line-Tabellen und Galerien
|
* INTERN: Robustes Rendern von Multi-line-Tabellen und Galerien (V1.2b)
|
||||||
*/
|
*/
|
||||||
_renderTable(meta, lines) {
|
_renderTable(meta, lines) {
|
||||||
let tableHtml = '<table>\n';
|
let tableHtml = '<table>\n';
|
||||||
let currentCells = [];
|
|
||||||
let cellBuffer = [];
|
|
||||||
let self = this;
|
|
||||||
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
let colCount = 0;
|
||||||
let line = lines[i];
|
if (meta) {
|
||||||
let parts = line.split('|');
|
let metaParts = meta.trim().split(/\s+/);
|
||||||
for (let j = 0; j < parts.length; j++) {
|
if (metaParts.length === 1 && metaParts[0].endsWith('x')) {
|
||||||
let part = parts[j];
|
colCount = parseInt(metaParts[0]);
|
||||||
|
|
||||||
if (j === parts.length - 1) {
|
|
||||||
if (part.trim() !== '') {
|
|
||||||
cellBuffer.push(part);
|
|
||||||
}
|
|
||||||
if (line.endsWith('|') && cellBuffer.length > 0) {
|
|
||||||
currentCells.push(cellBuffer.join('\n'));
|
|
||||||
cellBuffer = [];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cellBuffer.push(part);
|
colCount = metaParts.length;
|
||||||
currentCells.push(cellBuffer.join('\n'));
|
|
||||||
cellBuffer = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.endsWith('|') && currentCells.length > 0) {
|
let fullContent = lines.join('\n');
|
||||||
let rowContent = currentCells.map(function(c) {
|
let rawCells = fullContent.split('|');
|
||||||
let parsedCell = self._parseInline(c.trim()).replace(/\n/g, '<br>');
|
|
||||||
return `<td>${parsedCell}</td>`;
|
if (rawCells.length > 1 && rawCells[rawCells.length - 1].trim() === '') {
|
||||||
}).join('\n');
|
rawCells.pop();
|
||||||
tableHtml += `<tr>\n${rowContent}\n</tr>\n`;
|
}
|
||||||
currentCells = [];
|
|
||||||
|
let currentConfiguredCols = colCount || 1;
|
||||||
|
let cellIndex = 0;
|
||||||
|
|
||||||
|
tableHtml += '<tr>\n';
|
||||||
|
|
||||||
|
for (let i = 0; i < rawCells.length; i++) {
|
||||||
|
let cellText = rawCells[i].trim();
|
||||||
|
let parsedCell = this._parseInline(cellText).replace(/\n/g, '<br>');
|
||||||
|
tableHtml += ` <td>${parsedCell}</td>\n`;
|
||||||
|
|
||||||
|
cellIndex++;
|
||||||
|
|
||||||
|
if (cellIndex === currentConfiguredCols && i < rawCells.length - 1) {
|
||||||
|
tableHtml += '</tr>\n<tr>\n';
|
||||||
|
cellIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tableHtml += '</table>';
|
|
||||||
|
tableHtml += '</tr>\n</table>';
|
||||||
return tableHtml;
|
return tableHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERN: Verarbeitet Fluss-Formatierungen (Inline) mittels V1.2-RegEx
|
* INTERN: Verarbeitet Fluss-Formatierungen (Inline)
|
||||||
*/
|
*/
|
||||||
_parseInline(text) {
|
_parseInline(text) {
|
||||||
if (!text) return '';
|
if (!text) return '';
|
||||||
|
|
@ -223,15 +227,37 @@ class SimonUp {
|
||||||
|
|
||||||
html = html.replace(/\/\/(( \s|$))/g, '$1');
|
html = html.replace(/\/\/(( \s|$))/g, '$1');
|
||||||
|
|
||||||
// 1. ZUERST: Die kritischen Doppel-Sterne (fett) verarbeiten
|
// Überschriften-Parsing via .replace() zur Verhinderung von Index-Shifts
|
||||||
|
html = html.replace(/^([1-6])x#\s*(.*)/gm, (match, level, titleAndRest) => {
|
||||||
|
let { title, rest } = this._extractHeadingRest(titleAndRest);
|
||||||
|
const numStr = this._getAutoNumber(parseInt(level));
|
||||||
|
const fullTitle = `${numStr} ${title}`;
|
||||||
|
const id = this._slugify(fullTitle);
|
||||||
|
this.headings.push({ level: parseInt(level), text: title, id: id });
|
||||||
|
return `<h${level} id="${id}">${fullTitle}</h${level}>${rest}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
html = html.replace(/^([1-6])-#\s*(.*)/gm, (match, level, titleAndRest) => {
|
||||||
|
let { title, rest } = this._extractHeadingRest(titleAndRest);
|
||||||
|
return `<h${level}>${title}</h${level}>${rest}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
html = html.replace(/^([1-6])#\s*(.*)/gm, (match, level, titleAndRest) => {
|
||||||
|
let { title, rest } = this._extractHeadingRest(titleAndRest);
|
||||||
|
const id = this._slugify(title);
|
||||||
|
this.headings.push({ level: parseInt(level), text: title, id: id });
|
||||||
|
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>');
|
||||||
html = html.replace(/\*\*(.+?)(?=\*\*|$)/g, '<strong>$1</strong>');
|
html = html.replace(/\*\*(.+?)(?=\*\*|$)/g, '<strong>$1</strong>');
|
||||||
|
|
||||||
// 2. DANACH: Das einzelne Sternchen (medium) separat behandeln, damit es keine Tags beschädigt
|
// 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>');
|
||||||
html = html.replace(/\*(.+?)(?=\*|$)/g, '<span style="font-weight: 500;">$1</span>');
|
html = html.replace(/\*(.+?)(?=\*|$)/g, '<span style="font-weight: 500;">$1</span>');
|
||||||
|
|
||||||
// 3. Restliche Standard Text-Inline-Rules parsen
|
// Standard Text-Inline-Rules
|
||||||
const inlineRules = [
|
const inlineRules = [
|
||||||
{ tag: 'em', symbol: '%' },
|
{ tag: 'em', symbol: '%' },
|
||||||
{ tag: 'u', symbol: '_' },
|
{ tag: 'u', symbol: '_' },
|
||||||
|
|
@ -253,47 +279,7 @@ class SimonUp {
|
||||||
html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
|
html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Überschriften generieren
|
// Ausrichtungen, Links, Medien
|
||||||
let self = this;
|
|
||||||
const processHeading = function(pattern, callback) {
|
|
||||||
let match;
|
|
||||||
while ((match = pattern.exec(html)) !== null) {
|
|
||||||
const fullMatch = match[0];
|
|
||||||
const level = parseInt(match[1]);
|
|
||||||
const titleAndRest = match[2];
|
|
||||||
|
|
||||||
let title = titleAndRest;
|
|
||||||
let rest = "";
|
|
||||||
const closeIdx = titleAndRest.indexOf('/#');
|
|
||||||
if (closeIdx !== -1) {
|
|
||||||
title = titleAndRest.substring(0, closeIdx);
|
|
||||||
rest = titleAndRest.substring(closeIdx + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = callback(level, title.trim(), rest);
|
|
||||||
html = html.substring(0, match.index) + result + html.substring(match.index + fullMatch.length);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
processHeading(/^([1-6])x#\s*(.*)/g, function(level, title, rest) {
|
|
||||||
const numStr = self._getAutoNumber(level);
|
|
||||||
const fullTitle = `${numStr} ${title}`;
|
|
||||||
const id = self._slugify(fullTitle);
|
|
||||||
self.headings.push({ level: level, text: title, id: id });
|
|
||||||
return `<h${level} id="${id}">${fullTitle}</h${level}>${rest}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
processHeading(/^([1-6])-#\s*(.*)/g, function(level, title, rest) {
|
|
||||||
return `<h${level}>${title}</h${level}>${rest}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
processHeading(/^([1-6])#\s*(.*)/g, function(level, title, rest) {
|
|
||||||
const id = self._slugify(title);
|
|
||||||
self.headings.push({ level: level, text: title, id: id });
|
|
||||||
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 5. RESTLICHE STRUKTUREN (Ausrichtungen, Links, Medien)
|
|
||||||
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>`;
|
||||||
|
|
@ -314,6 +300,20 @@ class SimonUp {
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* INTERN: Hilfsmethode zur Extraktion des optionalen /# Abschlusses bei Überschriften
|
||||||
|
*/
|
||||||
|
_extractHeadingRest(text) {
|
||||||
|
let title = text;
|
||||||
|
let rest = "";
|
||||||
|
const closeIdx = text.indexOf('/#');
|
||||||
|
if (closeIdx !== -1) {
|
||||||
|
title = text.substring(0, closeIdx);
|
||||||
|
rest = text.substring(closeIdx + 2);
|
||||||
|
}
|
||||||
|
return { title: title.trim(), rest: rest };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERN: Errechnet die nächste fortlaufende Kapitelnummer
|
* INTERN: Errechnet die nächste fortlaufende Kapitelnummer
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue