Update Core.js

This commit is contained in:
simonpipe 2026-07-09 18:20:56 +02:00
parent 72bae28400
commit 91efaa66b1

87
Core.js
View file

@ -94,10 +94,12 @@ class SimonUp {
if (trimmed === '___') { if (trimmed === '___') {
result.push('<hr>'); result.push('<hr>');
} else if (trimmed.startsWith('- ')) { } else if (trimmed.startsWith('- ')) {
result.push('<ul-item>' + this._parseInline(line.replace(/^\s*-\s+/, '')) + '</ul-item>'); let insideUl = this._parseInline(line.replace(/^\s*-\s+/, ''));
result.push(`<ul-item>${insideUl}</ul-item>`);
} else if (/^\d+\.\s+/.test(trimmed)) { } else if (/^\d+\.\s+/.test(trimmed)) {
let cleanLine = line.replace(/^\s*\d+\.\s+/, ''); let cleanLine = line.replace(/^\s*\d+\.\s+/, '');
result.push('<ol-item>' + this._parseInline(cleanLine) + '</ol-item>'); let insideOl = this._parseInline(cleanLine);
result.push(`<ol-item>${insideOl}</ol-item>`);
} else { } else {
result.push(this._parseInline(line)); result.push(this._parseInline(line));
} }
@ -112,6 +114,7 @@ class SimonUp {
*/ */
_renderBlock(type, meta, lines) { _renderBlock(type, meta, lines) {
const content = lines.join('\n'); const content = lines.join('\n');
let self = this;
switch (type) { switch (type) {
case 'toc': case 'toc':
@ -119,44 +122,45 @@ class SimonUp {
if (meta || content.trim()) { if (meta || content.trim()) {
tocWrapper = '<div class="simonup-toc-wrapper">\n'; tocWrapper = '<div class="simonup-toc-wrapper">\n';
if (meta) { if (meta) {
tocWrapper += '<h2>' + meta + '</h2>\n'; tocWrapper += `<h2>${meta}</h2>\n`;
} }
if (content.trim()) { if (content.trim()) {
let self = this;
const intro = lines.map(function(l) { return self._parseInline(l); }).join('<br>'); const intro = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
tocWrapper += '<p class="toc-intro">' + intro + '</p>\n'; tocWrapper += `<p class="toc-intro">${intro}</p>\n`;
} }
tocWrapper += '\n</div>'; tocWrapper += '\n</div>';
} }
return tocWrapper; return tocWrapper;
case 'c': case 'c':
const langClass = meta ? ' class="language-' + meta + '"' : ''; const langClass = meta ? ` class="language-${meta}"` : '';
const escapedCode = content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); const escapedCode = content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return '<pre><code' + langClass + '>' + escapedCode + '</code></pre>'; return `<pre><code${langClass}>${escapedCode}</code></pre>`;
case 'q': case 'q':
let selfQ = this; const qContent = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
return '<blockquote>' + lines.map(function(l) { return selfQ._parseInline(l); }).join('<br>') + '</blockquote>'; return `<blockquote>${qContent}</blockquote>`;
case 'b': case 'b':
let selfB = this; const bContent = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
return '<div class="bible-block">' + lines.map(function(l) { return selfB._parseInline(l); }).join('<br>') + '</div>'; return `<div class="bible-block">${bContent}</div>`;
case 'f': case 'f':
let selfF = this; const fSummary = meta || 'Details';
return '<details>\n<summary>' + (meta || 'Details') + '</summary>\n<p>' + lines.map(function(l) { return selfF._parseInline(l); }).join('<br>') + '</p>\n</details>'; const fContent = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
return `<details>\n<summary>${fSummary}</summary>\n<p>${fContent}</p>\n</details>`;
case 'i': case 'i':
let selfI = this; const iColor = meta || '#ff6347';
return '<div class="infobox" style="border-left: 4px solid ' + (meta || '#ff6347') + '; padding: 10px; margin: 10px 0; background: #f8f9fa;">\n' + lines.map(function(l) { return selfI._parseInline(l); }).join('<br>') + '\n</div>'; const iContent = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
return `<div class="infobox" style="border-left: 4px solid ${iColor}; padding: 10px; margin: 10px 0; background: #f8f9fa;">\n${iContent}\n</div>`;
case 't': case 't':
return this._renderTable(meta, lines); return this._renderTable(meta, lines);
default: default:
let selfDef = this; const defContent = lines.map(function(l) { return self._parseInline(l); }).join('<br>');
return '<div class="block-' + type + '">' + lines.map(function(l) { return selfDef._parseInline(l); }).join('<br>') + '</div>'; return `<div class="block-${type}">${defContent}</div>`;
} }
} }
@ -192,9 +196,10 @@ class SimonUp {
if (line.endsWith('|') && currentCells.length > 0) { if (line.endsWith('|') && currentCells.length > 0) {
let rowContent = currentCells.map(function(c) { let rowContent = currentCells.map(function(c) {
return '<td>' + self._parseInline(c.trim()).replace(/\n/g, '<br>') + '</td>'; let parsedCell = self._parseInline(c.trim()).replace(/\n/g, '<br>');
return `<td>${parsedCell}</td>`;
}).join('\n'); }).join('\n');
tableHtml += '<tr>\n' + rowContent + '\n</tr>\n'; tableHtml += `<tr>\n${rowContent}\n</tr>\n`;
currentCells = []; currentCells = [];
} }
} }
@ -212,7 +217,7 @@ class SimonUp {
const escapes = []; const escapes = [];
html = html.replace(/\\(.)/g, function(match, char) { html = html.replace(/\\(.)/g, function(match, char) {
escapes.push(char); escapes.push(char);
return ''; return ``;
}); });
html = html.replace(/\/\/(\s|$)/g, '$1'); html = html.replace(/\/\/(\s|$)/g, '$1');
@ -240,20 +245,20 @@ class SimonUp {
processHeading(/^([1-6])x#\s*(.*)/g, function(level, title, rest) { processHeading(/^([1-6])x#\s*(.*)/g, function(level, title, rest) {
const numStr = self._getAutoNumber(level); const numStr = self._getAutoNumber(level);
const fullTitle = numStr + ' ' + title; const fullTitle = `${numStr} ${title}`;
const id = self._slugify(fullTitle); const id = self._slugify(fullTitle);
self.headings.push({ level: level, text: fullTitle, id: id }); self.headings.push({ level: level, text: fullTitle, id: id });
return '<h' + level + ' id="' + id + '">' + fullTitle + '</h' + level + '>' + rest; return `<h${level} id="${id}">${fullTitle}</h${level}>${rest}`;
}); });
processHeading(/^([1-6])-#\s*(.*)/g, function(level, title, rest) { processHeading(/^([1-6])-#\s*(.*)/g, function(level, title, rest) {
return '<h' + level + '>' + title + '</h' + level + '>' + rest; return `<h${level}>${title}</h${level}>${rest}`;
}); });
processHeading(/^([1-6])#\s*(.*)/g, function(level, title, rest) { processHeading(/^([1-6])#\s*(.*)/g, function(level, title, rest) {
const id = self._slugify(title); const id = self._slugify(title);
self.headings.push({ level: level, text: title, id: id }); self.headings.push({ level: level, text: title, id: id });
return '<h' + level + ' id="' + id + '">' + title + '</h' + level + '>' + rest; return `<h${level} id="${id}">${title}</h${level}>${rest}`;
}); });
const inlineRules = [ const inlineRules = [
@ -270,18 +275,20 @@ 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 regex = new RegExp(rule.symbol + '(.+?)\\x2F' + rule.symbol, 'g'); let regex = new RegExp(rule.symbol + '(.+?)\\x2F' + rule.symbol, 'g');
html = html.replace(regex, '<' + rule.tag + '>$1</' + rule.tag.split(' ')[0] + '>'); html = html.replace(regex, `<${rule.tag}>$1</${tagSimple}>`);
let resetRegex = new RegExp(rule.symbol + '(.+?)(?=)', 'g'); let resetRegex = new RegExp(rule.symbol + '(.+?)(?=)', 'g');
html = html.replace(resetRegex, '<' + rule.tag + '>$1</' + rule.tag.split(' ')[0] + '>'); html = html.replace(resetRegex, `<${rule.tag}>$1</${tagSimple}>`);
} }
html = html.replace(//g, ''); html = html.replace(//g, '');
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(/!\[([^\]]+)\s+w:(\d+)\]\(([^)]+)\)/g, '<img src="$3" alt="$1" style="width: $2px; height: auto;">');
@ -325,8 +332,12 @@ class SimonUp {
* INTERN: Erzeugt die fertige HTML-Liste des TOC und injiziert sie in den Block * INTERN: Erzeugt die fertige HTML-Liste des TOC und injiziert sie in den Block
*/ */
_injectTOC(html) { _injectTOC(html) {
if (!html.includes('')) return html; if (!html.includes('')) {
if (this.headings.length === 0) return html.replace('', ''); return html;
}
if (this.headings.length === 0) {
return html.replace('', '');
}
let tocListHtml = '<div class="simonup-toc">\n<ul>\n'; let tocListHtml = '<div class="simonup-toc">\n<ul>\n';
let currentLevel = 1; let currentLevel = 1;
@ -334,16 +345,19 @@ class SimonUp {
for (let i = 0; i < this.headings.length; i++) { for (let i = 0; i < this.headings.length; i++) {
let heading = this.headings[i]; let heading = this.headings[i];
if (heading.level > currentLevel) { if (heading.level > currentLevel) {
tocListHtml += '<ul>\n'.repeat(heading.level - currentLevel); let diffUp = heading.level - currentLevel;
tocListHtml += '<ul>\n'.repeat(diffUp);
} else if (heading.level < currentLevel) { } else if (heading.level < currentLevel) {
tocListHtml += '</ul>\n'.repeat(currentLevel - heading.level); let diffDown = currentLevel - heading.level;
tocListHtml += '</ul>\n'.repeat(diffDown);
} }
currentLevel = heading.level; currentLevel = heading.level;
tocListHtml += '<li><a href="#' + heading.id + '">' + heading.text + '</a></li>\n'; tocListHtml += `<li><a href="#${heading.id}">${heading.text}</a></li>\n`;
} }
if (currentLevel > 1) { if (currentLevel > 1) {
tocListHtml += '</ul>\n'.repeat(currentLevel - 1); let diffFinal = currentLevel - 1;
tocListHtml += '</ul>\n'.repeat(diffFinal);
} }
tocListHtml += '</ul>\n</div>'; tocListHtml += '</ul>\n</div>';
@ -361,8 +375,8 @@ class SimonUp {
const flushList = function() { const flushList = function() {
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>${item}</li>`; }).join('\n');
processed.push('<' + currentListType + '>\n' + items + '\n</' + currentListType + '>'); processed.push(`<${currentListType}>\n${items}\n</${currentListType}>`);
listBuffer = []; listBuffer = [];
currentListType = null; currentListType = null;
} }
@ -370,7 +384,8 @@ class SimonUp {
const flushParagraph = function() { const flushParagraph = function() {
if (paragraphBuffer.length > 0) { if (paragraphBuffer.length > 0) {
processed.push('<p>' + paragraphBuffer.join('<br>') + '</p>'); let pContent = paragraphBuffer.join('<br>');
processed.push(`<p>${pContent}</p>`);
paragraphBuffer = []; paragraphBuffer = [];
} }
}; };