From 72bae284007122427b41f932ce31efe460eca894 Mon Sep 17 00:00:00 2001 From: simonpipe Date: Thu, 9 Jul 2026 18:13:57 +0200 Subject: [PATCH] Update Core.js --- Core.js | 145 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 58 deletions(-) diff --git a/Core.js b/Core.js index c922743..11b43f6 100644 --- a/Core.js +++ b/Core.js @@ -5,8 +5,8 @@ class SimonUp { constructor() { this.plugins = []; - this.headings = []; // Speichert alle gefundenen Überschriften für das TOC - this.counters = [0, 0, 0, 0, 0, 0]; // Zähler für die hierarchischen Ebenen 1 bis 6 + this.headings = []; + this.counters = [0, 0, 0, 0, 0, 0]; } /** @@ -26,15 +26,23 @@ class SimonUp { let html = text; - for (const plugin of this.plugins) { - if (plugin.before) html = plugin.before(html); + if (this.plugins && this.plugins.length > 0) { + for (let i = 0; i < this.plugins.length; i++) { + if (this.plugins[i].before) { + html = this.plugins[i].before(html); + } + } } html = this._parseBlocks(html); html = this._injectTOC(html); - for (const plugin of this.plugins) { - if (plugin.after) html = plugin.after(html); + if (this.plugins && this.plugins.length > 0) { + for (let i = 0; i < this.plugins.length; i++) { + if (this.plugins[i].after) { + html = this.plugins[i].after(html); + } + } } return html; @@ -86,10 +94,10 @@ class SimonUp { if (trimmed === '___') { result.push('
'); } else if (trimmed.startsWith('- ')) { - result.push(`${this._parseInline(line.replace(/^\s*-\s+/, ''))}`); + result.push('' + this._parseInline(line.replace(/^\s*-\s+/, '')) + ''); } else if (/^\d+\.\s+/.test(trimmed)) { let cleanLine = line.replace(/^\s*\d+\.\s+/, ''); - result.push(`${this._parseInline(cleanLine)}`); + result.push('' + this._parseInline(cleanLine) + ''); } else { result.push(this._parseInline(line)); } @@ -107,40 +115,48 @@ class SimonUp { switch (type) { case 'toc': - let tocWrapper = ``; + let tocWrapper = ''; if (meta || content.trim()) { - tocWrapper = `
\n`; - if (meta) tocWrapper += `

${meta}

\n`; - if (content.trim()) { - const intro = lines.map(l => this._parseInline(l)).join('
'); - tocWrapper += `

${intro}

\n`; + tocWrapper = '
\n'; + if (meta) { + tocWrapper += '

' + meta + '

\n'; } - tocWrapper += `\n
`; + if (content.trim()) { + let self = this; + const intro = lines.map(function(l) { return self._parseInline(l); }).join('
'); + tocWrapper += '

' + intro + '

\n'; + } + tocWrapper += '\n
'; } return tocWrapper; case 'c': - const langClass = meta ? ` class="language-${meta}"` : ''; + const langClass = meta ? ' class="language-' + meta + '"' : ''; const escapedCode = content.replace(/&/g, '&').replace(//g, '>'); - return `
${escapedCode}
`; + return '
' + escapedCode + '
'; case 'q': - return `
${lines.map(l => this._parseInline(l)).join('
')}
`; + let selfQ = this; + return '
' + lines.map(function(l) { return selfQ._parseInline(l); }).join('
') + '
'; case 'b': - return `
${lines.map(l => this._parseInline(l)).join('
')}
`; + let selfB = this; + return '
' + lines.map(function(l) { return selfB._parseInline(l); }).join('
') + '
'; case 'f': - return `
\n${meta || 'Details'}\n

${lines.map(l => this._parseInline(l)).join('
')}

\n
`; + let selfF = this; + return '
\n' + (meta || 'Details') + '\n

' + lines.map(function(l) { return selfF._parseInline(l); }).join('
') + '

\n
'; case 'i': - return `
\n${lines.map(l => this._parseInline(l)).join('
')}\n
`; + let selfI = this; + return '
\n' + lines.map(function(l) { return selfI._parseInline(l); }).join('
') + '\n
'; case 't': return this._renderTable(meta, lines); default: - return `
${lines.map(l => this._parseInline(l)).join('
')}
`; + let selfDef = this; + return '
' + lines.map(function(l) { return selfDef._parseInline(l); }).join('
') + '
'; } } @@ -151,13 +167,15 @@ class SimonUp { let tableHtml = '\n'; let currentCells = []; let cellBuffer = []; + let self = this; - for (let line of lines) { + for (let i = 0; i < lines.length; i++) { + let line = lines[i]; let parts = line.split('|'); - for (let i = 0; i < parts.length; i++) { - let part = parts[i]; + for (let j = 0; j < parts.length; j++) { + let part = parts[j]; - if (i === parts.length - 1) { + if (j === parts.length - 1) { if (part.trim() !== '') { cellBuffer.push(part); } @@ -173,7 +191,10 @@ class SimonUp { } if (line.endsWith('|') && currentCells.length > 0) { - tableHtml += '\n' + currentCells.map(c => ``).join('\n') + '\n\n'; + let rowContent = currentCells.map(function(c) { + return ''; + }).join('\n'); + tableHtml += '\n' + rowContent + '\n\n'; currentCells = []; } } @@ -189,14 +210,15 @@ class SimonUp { let html = text; const escapes = []; - html = html.replace(/\\(.)/g, (match, char) => { + html = html.replace(/\\(.)/g, function(match, char) { escapes.push(char); - return ``; + return ''; }); html = html.replace(/\/\/(\s|$)/g, '$1'); - const processHeading = (pattern, callback) => { + let self = this; + const processHeading = function(pattern, callback) { let match; while ((match = pattern.exec(html)) !== null) { const fullMatch = match[0]; @@ -216,22 +238,22 @@ class SimonUp { } }; - processHeading(/^([1-6])x#\s*(.*)/g, (level, title, rest) => { - const numStr = this._getAutoNumber(level); - const fullTitle = `${numStr} ${title}`; - const id = this._slugify(fullTitle); - this.headings.push({ level, text: fullTitle, id }); - return `${fullTitle}${rest}`; + 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: fullTitle, id: id }); + return '' + fullTitle + '' + rest; }); - processHeading(/^([1-6])-#\s*(.*)/g, (level, title, rest) => { - return `${title}${rest}`; + processHeading(/^([1-6])-#\s*(.*)/g, function(level, title, rest) { + return '' + title + '' + rest; }); - processHeading(/^([1-6])#\s*(.*)/g, (level, title, rest) => { - const id = this._slugify(title); - this.headings.push({ level, text: title, id }); - return `${title}${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 '' + title + '' + rest; }); const inlineRules = [ @@ -246,20 +268,20 @@ class SimonUp { { tag: 'code', symbol: '`' } ]; - // Hier nutzen wir nun eine absolut sichere String-Verkettung für den RegExp-Konstruktor - for (const rule of inlineRules) { + for (let k = 0; k < inlineRules.length; k++) { + let rule = inlineRules[k]; let regex = new RegExp(rule.symbol + '(.+?)\\x2F' + rule.symbol, 'g'); - html = html.replace(regex, `<${rule.tag}>$1`); + html = html.replace(regex, '<' + rule.tag + '>$1'); let resetRegex = new RegExp(rule.symbol + '(.+?)(?=)', 'g'); - html = html.replace(resetRegex, `<${rule.tag}>$1`); + html = html.replace(resetRegex, '<' + rule.tag + '>$1'); } html = html.replace(//g, ''); - const alignMap = { l: 'left', r: 'right', c: 'center', j: 'justify' }; - html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, (m, dir, content) => { - return `
${content}
`; + const alignMap = { 'l': 'left', 'r': 'right', 'c': 'center', 'j': 'justify' }; + html = html.replace(/>([lrcj])\s+(.+?)\s*\/>/g, function(m, dir, content) { + return '
' + content + '
'; }); html = html.replace(/!\[([^\]]+)\s+w:(\d+)\]\(([^)]+)\)/g, '$1'); @@ -270,7 +292,9 @@ class SimonUp { html = html.replace(/\^x\[([^\]]+)\]\^/g, '[*]'); html = html.replace(/\^(\d+)\[([^\]]+)\]\^/g, '[$1]'); - html = html.replace(//g, (match, idx) => escapes[idx]); + html = html.replace(//g, function(match, idx) { + return escapes[idx]; + }); return html; } @@ -281,7 +305,9 @@ class SimonUp { _getAutoNumber(level) { let idx = level - 1; this.counters[idx]++; - for (let i = idx + 1; i < 6; i++) this.counters[i] = 0; + for (let i = idx + 1; i < 6; i++) { + this.counters[i] = 0; + } let activeParts = this.counters.slice(0, level); return activeParts.join('.') + '.'; } @@ -305,14 +331,15 @@ class SimonUp { let tocListHtml = '
\n
${this._parseInline(c.trim()).replace(/\n/g, '
')}
' + self._parseInline(c.trim()).replace(/\n/g, '
') + '