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 => `${this._parseInline(c.trim()).replace(/\n/g, ' ')} | `).join('\n') + '\n
\n';
+ let rowContent = currentCells.map(function(c) {
+ return '' + self._parseInline(c.trim()).replace(/\n/g, ' ') + ' | ';
+ }).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${rule.tag.split(' ')[0]}>`);
+ html = html.replace(regex, '<' + rule.tag + '>$1' + rule.tag.split(' ')[0] + '>');
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' + rule.tag.split(' ')[0] + '>');
}
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, '
');
@@ -270,7 +292,9 @@ class SimonUp {
html = html.replace(/\^x\[([^\]]+)\]\^/g, '');
html = html.replace(/\^(\d+)\[([^\]]+)\]\^/g, '');
- 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
\n';
let currentLevel = 1;
- for (const heading of this.headings) {
+ for (let i = 0; i < this.headings.length; i++) {
+ let heading = this.headings[i];
if (heading.level > currentLevel) {
tocListHtml += '\n'.repeat(heading.level - currentLevel);
} else if (heading.level < currentLevel) {
tocListHtml += '
\n'.repeat(currentLevel - heading.level);
}
currentLevel = heading.level;
- tocListHtml += `- ${heading.text}
\n`;
+ tocListHtml += '- ' + heading.text + '
\n';
}
if (currentLevel > 1) {
@@ -332,22 +359,24 @@ class SimonUp {
let listBuffer = [];
let currentListType = null;
- const flushList = () => {
+ const flushList = function() {
if (listBuffer.length > 0) {
- processed.push(`<${currentListType}>\n` + listBuffer.map(item => ` - ${item}
`).join('\n') + `\n${currentListType}>`);
+ let items = listBuffer.map(function(item) { return ' - ' + item + '
'; }).join('\n');
+ processed.push('<' + currentListType + '>\n' + items + '\n' + currentListType + '>');
listBuffer = [];
currentListType = null;
}
};
- const flushParagraph = () => {
+ const flushParagraph = function() {
if (paragraphBuffer.length > 0) {
- processed.push(`${paragraphBuffer.join('
')}
`);
+ processed.push('' + paragraphBuffer.join('
') + '
');
paragraphBuffer = [];
}
};
- for (let element of elements) {
+ for (let i = 0; i < elements.length; i++) {
+ let element = elements[i];
let isUlItem = element.startsWith('');
let isOlItem = element.startsWith('');