Update Core.js
This commit is contained in:
parent
ab47566482
commit
3f0fe24875
1 changed files with 90 additions and 106 deletions
196
Core.js
196
Core.js
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* SimonUp Core Compiler (Core.js) - Version 1.2b.003
|
* SimonUp Core Compiler (Core.js) - Version 1.2b.004
|
||||||
* Eine moderne, fluss- und blockorientierte Auszeichnungssprache.
|
* Eine moderne, fluss- und blockorientierte Auszeichnungssprache.
|
||||||
*/
|
*/
|
||||||
class SimonUp {
|
class SimonUp {
|
||||||
|
|
@ -7,22 +7,18 @@ class SimonUp {
|
||||||
this.plugins = [];
|
this.plugins = [];
|
||||||
this.headings = [];
|
this.headings = [];
|
||||||
this.counters = [0, 0, 0, 0, 0, 0];
|
this.counters = [0, 0, 0, 0, 0, 0];
|
||||||
|
this.currentFootnotes = []; // Sammelt Fußnoten für den aktuellen Abschnitt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Registriert eine Erweiterung (Plugin)
|
|
||||||
*/
|
|
||||||
use(plugin) {
|
use(plugin) {
|
||||||
this.plugins.push(plugin);
|
this.plugins.push(plugin);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hauptfunktion: Wandelt SimonUp-Text (.up) in valides HTML um
|
|
||||||
*/
|
|
||||||
parse(text) {
|
parse(text) {
|
||||||
this.headings = [];
|
this.headings = [];
|
||||||
this.counters = [0, 0, 0, 0, 0, 0];
|
this.counters = [0, 0, 0, 0, 0, 0];
|
||||||
|
this.currentFootnotes = [];
|
||||||
|
|
||||||
let html = text;
|
let html = text;
|
||||||
|
|
||||||
|
|
@ -34,10 +30,10 @@ class SimonUp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase 1: Blöcke und Inline-Strukturen parsen
|
// Phase 1: Strukturelle Blöcke isolieren
|
||||||
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 injizieren
|
||||||
html = this._injectTOC(html);
|
html = this._injectTOC(html);
|
||||||
|
|
||||||
if (this.plugins && this.plugins.length > 0) {
|
if (this.plugins && this.plugins.length > 0) {
|
||||||
|
|
@ -51,9 +47,6 @@ class SimonUp {
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Verarbeitet strukturelle Blöcke und freie Strukturen zeilenweise
|
|
||||||
*/
|
|
||||||
_parseBlocks(text) {
|
_parseBlocks(text) {
|
||||||
const lines = text.replace(/\r\n/g, '\n').split('\n');
|
const lines = text.replace(/\r\n/g, '\n').split('\n');
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
@ -64,9 +57,24 @@ 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];
|
||||||
|
let trimmed = line.trim();
|
||||||
|
|
||||||
// Block-Start erkennen (&typ meta)
|
// Block-Ende erkennen mit /&
|
||||||
if (!inBlock && line.startsWith('&') && line.trim().length > 1) {
|
if (inBlock && trimmed.replace(/\u00A0/g, ' ') === '/&') {
|
||||||
|
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
||||||
|
inBlock = false;
|
||||||
|
blockType = null;
|
||||||
|
blockMeta = "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inBlock) {
|
||||||
|
blockBuffer.push(line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block-Start erkennen
|
||||||
|
if (line.startsWith('&') && trimmed.length > 1) {
|
||||||
inBlock = true;
|
inBlock = true;
|
||||||
const fullHeader = line.substring(1).trim();
|
const fullHeader = line.substring(1).trim();
|
||||||
const spaceIndex = fullHeader.indexOf(' ');
|
const spaceIndex = fullHeader.indexOf(' ');
|
||||||
|
|
@ -82,46 +90,38 @@ class SimonUp {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block-Ende erkennen mit /&
|
// Überschriften abfangen, um vorherige Fußnoten zu flushen
|
||||||
if (inBlock && line.trim().replace(/\u00A0/g, ' ') === '/&') {
|
if (/^([1-6])(x|-)?#\s*/.test(trimmed)) {
|
||||||
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
let footnoteBlock = this._flushFootnotes();
|
||||||
inBlock = false;
|
if (footnoteBlock) result.push(footnoteBlock);
|
||||||
blockType = null;
|
|
||||||
blockMeta = "";
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBlock) {
|
// Freie Linien und Listen-Strukturen
|
||||||
blockBuffer.push(line);
|
if (trimmed === '___') {
|
||||||
|
result.push('<hr>');
|
||||||
|
} else if (trimmed.startsWith('- ')) {
|
||||||
|
let insideUl = this._parseInline(line.replace(/^\s*-\s+/, ''));
|
||||||
|
result.push(`<ul-item>${insideUl}</ul-item>`);
|
||||||
|
} else if (/^\d+\.\s+/.test(trimmed)) {
|
||||||
|
let cleanLine = line.replace(/^\s*\d+\.\s+/, '');
|
||||||
|
let insideOl = this._parseInline(cleanLine);
|
||||||
|
result.push(`<ol-item>${insideOl}</ol-item>`);
|
||||||
} else {
|
} else {
|
||||||
let trimmed = line.trim();
|
result.push(this._parseInline(line));
|
||||||
|
|
||||||
if (trimmed === '___') {
|
|
||||||
result.push('<hr>');
|
|
||||||
} else if (trimmed.startsWith('- ')) {
|
|
||||||
let insideUl = this._parseInline(line.replace(/^\s*-\s+/, ''));
|
|
||||||
result.push(`<ul-item>${insideUl}</ul-item>`);
|
|
||||||
} else if (/^\d+\.\s+/.test(trimmed)) {
|
|
||||||
let cleanLine = line.replace(/^\s*\d+\.\s+/, '');
|
|
||||||
let insideOl = this._parseInline(cleanLine);
|
|
||||||
result.push(`<ol-item>${insideOl}</ol-item>`);
|
|
||||||
} else {
|
|
||||||
result.push(this._parseInline(line));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatischer Schutz: Falls am Dateiende ein Block nicht geschlossen wurde
|
|
||||||
if (inBlock && blockBuffer.length > 0) {
|
if (inBlock && blockBuffer.length > 0) {
|
||||||
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
result.push(this._renderBlock(blockType, blockMeta, blockBuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Letzte Fußnoten am Ende des Dokuments anfügen
|
||||||
|
let finalFootnotes = this._flushFootnotes();
|
||||||
|
if (finalFootnotes) result.push(finalFootnotes);
|
||||||
|
|
||||||
return this._processParagraphsAndLists(result);
|
return this._processParagraphsAndLists(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Erzeugt das HTML für einen geschlossenen Block
|
|
||||||
*/
|
|
||||||
_renderBlock(type, meta, lines) {
|
_renderBlock(type, meta, lines) {
|
||||||
const content = lines.join('\n');
|
const content = lines.join('\n');
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
@ -172,12 +172,8 @@ class SimonUp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Robustes Rendern von Multi-line-Tabellen und Galerien
|
|
||||||
*/
|
|
||||||
_renderTable(meta, lines) {
|
_renderTable(meta, lines) {
|
||||||
let tableHtml = '<table>\n';
|
let tableHtml = '<table>\n';
|
||||||
|
|
||||||
let colCount = 0;
|
let colCount = 0;
|
||||||
if (meta) {
|
if (meta) {
|
||||||
let metaParts = meta.trim().split(/\s+/);
|
let metaParts = meta.trim().split(/\s+/);
|
||||||
|
|
@ -188,38 +184,35 @@ class SimonUp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fullContent = lines.join('\n');
|
let processedLines = lines
|
||||||
let rawCells = fullContent.split('|');
|
.map(l => l.trim())
|
||||||
|
.filter(l => l.length > 0)
|
||||||
if (rawCells.length > 1 && rawCells[rawCells.length - 1].trim() === '') {
|
.map(l => {
|
||||||
rawCells.pop();
|
if (l.startsWith('|')) l = l.substring(1);
|
||||||
}
|
if (l.endsWith('|')) l = l.slice(0, -1);
|
||||||
|
return l;
|
||||||
|
});
|
||||||
|
|
||||||
|
let fullContent = processedLines.join('|');
|
||||||
|
let rawCells = fullContent.split('|');
|
||||||
let currentConfiguredCols = colCount || 1;
|
let currentConfiguredCols = colCount || 1;
|
||||||
let cellIndex = 0;
|
let cellIndex = 0;
|
||||||
|
|
||||||
tableHtml += '<tr>\n';
|
tableHtml += '<tr>\n';
|
||||||
|
|
||||||
for (let i = 0; i < rawCells.length; i++) {
|
for (let i = 0; i < rawCells.length; i++) {
|
||||||
let cellText = rawCells[i].trim();
|
let cellText = rawCells[i].trim();
|
||||||
let parsedCell = this._parseInline(cellText).replace(/\n/g, '<br>');
|
let parsedCell = this._parseInline(cellText);
|
||||||
tableHtml += ` <td>${parsedCell}</td>\n`;
|
tableHtml += ` <td>${parsedCell}</td>\n`;
|
||||||
|
|
||||||
cellIndex++;
|
cellIndex++;
|
||||||
|
|
||||||
if (cellIndex === currentConfiguredCols && i < rawCells.length - 1) {
|
if (cellIndex === currentConfiguredCols && i < rawCells.length - 1) {
|
||||||
tableHtml += '</tr>\n<tr>\n';
|
tableHtml += '</tr>\n<tr>\n';
|
||||||
cellIndex = 0;
|
cellIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tableHtml += '</tr>\n</table>';
|
tableHtml += '</tr>\n</table>';
|
||||||
return tableHtml;
|
return tableHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Verarbeitet Fluss-Formatierungen (Inline) ohne HTML-Zerstörung
|
|
||||||
*/
|
|
||||||
_parseInline(text) {
|
_parseInline(text) {
|
||||||
if (!text) return '';
|
if (!text) return '';
|
||||||
let html = text;
|
let html = text;
|
||||||
|
|
@ -230,7 +223,7 @@ class SimonUp {
|
||||||
return `__ESCAPED_CHAR_${escapes.length - 1}__`;
|
return `__ESCAPED_CHAR_${escapes.length - 1}__`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 1. Überschriften ERST parsen (bevor HTML-Tags im Fluss entstehen)
|
// Überschriften parsen
|
||||||
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));
|
||||||
|
|
@ -252,23 +245,19 @@ class SimonUp {
|
||||||
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
return `<h${level} id="${id}">${title}</h${level}>${rest}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Medien & Links verarbeiten
|
// Medien & Links
|
||||||
html = html.replace(/!\[([^\]]+)\s+w:(\d+)\]\(([^)]+)\)/g, '<img src="$3" alt="$1" style="width: $2px; height: auto;">');
|
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, '<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" target="_blank" rel="noopener noreferrer">$1</a>');
|
||||||
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
||||||
|
|
||||||
// Hilfsfunktion: Führt Ersetzungen nur AUSSERHALB von HTML-Tags <...> aus
|
|
||||||
const replaceOutsideTags = (regex, replacement) => {
|
const replaceOutsideTags = (regex, replacement) => {
|
||||||
const masterRegex = new RegExp(/(<[^>]+>)/g.source + '|' + regex.source, 'g');
|
const masterRegex = new RegExp(/(<[^>]+>)/g.source + '|' + regex.source, 'g');
|
||||||
html = html.replace(masterRegex, (match, p1) => {
|
html = html.replace(masterRegex, (match, p1) => {
|
||||||
if (p1) return p1; // HTML-Tags überspringen
|
if (p1) return p1;
|
||||||
|
|
||||||
const innerMatch = regex.exec(match);
|
const innerMatch = regex.exec(match);
|
||||||
if (innerMatch) {
|
if (innerMatch) {
|
||||||
if (typeof replacement === 'function') {
|
if (typeof replacement === 'function') return replacement(...innerMatch);
|
||||||
return replacement(...innerMatch);
|
|
||||||
}
|
|
||||||
let res = replacement;
|
let res = replacement;
|
||||||
for (let idx = 1; idx < innerMatch.length; idx++) {
|
for (let idx = 1; idx < innerMatch.length; idx++) {
|
||||||
res = res.replace(new RegExp('\\$' + idx, 'g'), innerMatch[idx]);
|
res = res.replace(new RegExp('\\$' + idx, 'g'), innerMatch[idx]);
|
||||||
|
|
@ -279,13 +268,10 @@ class SimonUp {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 2. Formatierung für FETT (**text/** oder **text/)
|
// Exakte Trennung für Fett und Medium (Verhindert das Überschneiden)
|
||||||
replaceOutsideTags(/\*\*(.+?)(?:\/\*\*|\/|\*\*|$)/, '<strong>$1</strong>');
|
replaceOutsideTags(/\*\*([^*]+?)(?:\/\*\*|\/|\*\*|$)/, '<strong>$1</strong>');
|
||||||
|
replaceOutsideTags(/\*([^*]+?)(?:\/\*|\/|\*|$)/, '<span style="font-weight: 500;">$1</span>');
|
||||||
|
|
||||||
// 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: '_' },
|
||||||
|
|
@ -299,20 +285,27 @@ class SimonUp {
|
||||||
for (let k = 0; k < inlineRules.length; k++) {
|
for (let k = 0; k < inlineRules.length; k++) {
|
||||||
let rule = inlineRules[k];
|
let rule = inlineRules[k];
|
||||||
let tagSimple = rule.tag.split(' ')[0];
|
let tagSimple = rule.tag.split(' ')[0];
|
||||||
|
|
||||||
// Unterstützt %text/% sowie das Fallback %text am Zeilenende
|
|
||||||
replaceOutsideTags(new RegExp(rule.symbol + '(.+?)(?:\\/' + rule.symbol + '|\\/|' + rule.symbol + '|$)'), `<${rule.tag}>$1</${tagSimple}>`);
|
replaceOutsideTags(new RegExp(rule.symbol + '(.+?)(?:\\/' + rule.symbol + '|\\/|' + rule.symbol + '|$)'), `<${rule.tag}>$1</${tagSimple}>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ausrichtungen & Fußnoten
|
// Fußnoten abfangen und registrieren statt nur als Title zu setzen
|
||||||
|
let self = this;
|
||||||
|
html = html.replace(/\^x\[([^\]]+)\]\^x/g, function(m, content) {
|
||||||
|
self.currentFootnotes.push(content);
|
||||||
|
const num = self.currentFootnotes.length;
|
||||||
|
return `<sup class="footnote-auto" title="${content}">[${num}]</sup>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
html = html.replace(/\^(\d+)\[([^\]]+)\]\^x/g, function(m, num, content) {
|
||||||
|
self.currentFootnotes.push(`${num}: ${content}`);
|
||||||
|
return `<sup class="footnote-manual" title="${content}">[${num}]</sup>`;
|
||||||
|
});
|
||||||
|
|
||||||
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(/\^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(/__ESCAPED_CHAR_(\d+)__/g, function(match, idx) {
|
html = html.replace(/__ESCAPED_CHAR_(\d+)__/g, function(match, idx) {
|
||||||
return escapes[idx];
|
return escapes[idx];
|
||||||
});
|
});
|
||||||
|
|
@ -320,9 +313,18 @@ class SimonUp {
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Hilfsfunktion: Gibt gesammelte Fußnoten als HTML-Block aus und leert den Speicher
|
||||||
* INTERN: Hilfsmethode zur Extraktion des optionalen /# Abschlusses bei Überschriften
|
_flushFootnotes() {
|
||||||
*/
|
if (this.currentFootnotes.length === 0) return null;
|
||||||
|
let html = '<div class="simonup-footnotes" style="margin-top: 10px; margin-bottom: 20px; font-size: 0.85em; color: #555; border-top: 1px dashed #ddd; padding-top: 5px;">\n';
|
||||||
|
for (let i = 0; i < this.currentFootnotes.length; i++) {
|
||||||
|
html += `<div class="footnote-entry">${this.currentFootnotes[i]}</div>\n`;
|
||||||
|
}
|
||||||
|
html += '</div>';
|
||||||
|
this.currentFootnotes = []; // Zurücksetzen fürs nächste Kapitel
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
_extractHeadingRest(text) {
|
_extractHeadingRest(text) {
|
||||||
let title = text;
|
let title = text;
|
||||||
let rest = "";
|
let rest = "";
|
||||||
|
|
@ -334,9 +336,6 @@ class SimonUp {
|
||||||
return { title: title.trim(), rest: rest };
|
return { title: title.trim(), rest: rest };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Errechnet die nächste fortlaufende Kapitelnummer
|
|
||||||
*/
|
|
||||||
_getAutoNumber(level) {
|
_getAutoNumber(level) {
|
||||||
let idx = level - 1;
|
let idx = level - 1;
|
||||||
this.counters[idx]++;
|
this.counters[idx]++;
|
||||||
|
|
@ -347,28 +346,16 @@ class SimonUp {
|
||||||
return activeParts.join('.') + '.';
|
return activeParts.join('.') + '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Macht aus Text eine URL-konforme ID
|
|
||||||
*/
|
|
||||||
_slugify(text) {
|
_slugify(text) {
|
||||||
return text.toLowerCase()
|
return text.toLowerCase()
|
||||||
.replace(/[^a-z0-9\s-]/g, '')
|
.replace(/[^a-z0-9\s-]/g, '')
|
||||||
.replace(/\s+/g, '-');
|
.replace(/\s+/g, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Erzeugt die fertige HTML-Liste des TOC und injiziert sie in den Block
|
|
||||||
*/
|
|
||||||
_injectTOC(html) {
|
_injectTOC(html) {
|
||||||
const placeholder = 'STRENG_GEHEIMER_TOC_PLATZHALTER';
|
const placeholder = 'STRENG_GEHEIMER_TOC_PLATZHALTER';
|
||||||
|
if (!html.includes(placeholder)) return html;
|
||||||
if (!html.includes(placeholder)) {
|
if (this.headings.length === 0) return html.replace(placeholder, '');
|
||||||
return html;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.headings.length === 0) {
|
|
||||||
return html.replace(placeholder, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
let tocListHtml = '<div class="simonup-toc">\n<ul>\n';
|
let tocListHtml = '<div class="simonup-toc">\n<ul>\n';
|
||||||
let currentLevel = 1;
|
let currentLevel = 1;
|
||||||
|
|
@ -395,9 +382,6 @@ class SimonUp {
|
||||||
return html.replace(placeholder, tocListHtml);
|
return html.replace(placeholder, tocListHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERN: Fasst freie Listen-Elemente zusammen und generiert Absätze (p)
|
|
||||||
*/
|
|
||||||
_processParagraphsAndLists(elements) {
|
_processParagraphsAndLists(elements) {
|
||||||
let processed = [];
|
let processed = [];
|
||||||
let paragraphBuffer = [];
|
let paragraphBuffer = [];
|
||||||
|
|
@ -406,8 +390,8 @@ class SimonUp {
|
||||||
|
|
||||||
function flushList() {
|
function flushList() {
|
||||||
if (listBuffer.length > 0) {
|
if (listBuffer.length > 0) {
|
||||||
let items = listBuffer.map(function(item) { return " <li>" + item + "</li>"; }).join("\n");
|
let items = listBuffer.map(function(item) { return " <li style='margin-bottom: 4px;'>" + item + "</li>"; }).join("\n");
|
||||||
processed.push("<" + currentListType + ">\n" + items + "\n</" + currentListType + ">");
|
processed.push("<" + currentListType + " style='margin-bottom: 12px; margin-left: 20px;'>\n" + items + "\n</" + currentListType + ">");
|
||||||
listBuffer = [];
|
listBuffer = [];
|
||||||
currentListType = null;
|
currentListType = null;
|
||||||
}
|
}
|
||||||
|
|
@ -416,7 +400,7 @@ class SimonUp {
|
||||||
function flushParagraph() {
|
function flushParagraph() {
|
||||||
if (paragraphBuffer.length > 0) {
|
if (paragraphBuffer.length > 0) {
|
||||||
let pContent = paragraphBuffer.join("<br>");
|
let pContent = paragraphBuffer.join("<br>");
|
||||||
processed.push("<p>" + pContent + "</p>");
|
processed.push("<p style='margin-bottom: 12px;'>" + pContent + "</p>");
|
||||||
paragraphBuffer = [];
|
paragraphBuffer = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -438,7 +422,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[1-6])/i.test(element)) {
|
} else if (element.startsWith("<") && !/^(<a>|<strong>|<em>|<u>|<del>|<mark>|<sup>|<sub>|<span>|<code>|<img>|<h[1-6]|<table>|<thead|<tbody|<tr|<td)/i.test(element)) {
|
||||||
flushList();
|
flushList();
|
||||||
flushParagraph();
|
flushParagraph();
|
||||||
processed.push(element);
|
processed.push(element);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue