diff --git a/Playground/Core.js b/Playground/Core.js new file mode 100644 index 0000000..37c99e7 --- /dev/null +++ b/Playground/Core.js @@ -0,0 +1,444 @@ +/** + * SimonUp Core Compiler (Core.js) - Version 1.2b.005 + * Eine moderne, fluss- und blockorientierte Auszeichnungssprache. + */ +class SimonUp { + constructor() { + this.plugins = []; + this.headings = []; + this.counters = [0, 0, 0, 0, 0, 0]; + this.currentFootnotes = []; // Sammelt Fußnoten für den aktuellen Abschnitt + } + + use(plugin) { + this.plugins.push(plugin); + return this; + } + + parse(text) { + this.headings = []; + this.counters = [0, 0, 0, 0, 0, 0]; + this.currentFootnotes = []; + + let html = text; + + 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); + } + } + } + + // Phase 1: Strukturelle Blöcke isolieren + html = this._parseBlocks(html); + + // Phase 2: Das Inhaltsverzeichnis nachträglich injizieren + html = this._injectTOC(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; + } + + _parseBlocks(text) { + const lines = text.replace(/\r\n/g, '\n').split('\n'); + let result = []; + let inBlock = false; + let blockType = null; + let blockMeta = ""; + let blockBuffer = []; + + for (let i = 0; i < lines.length; i++) { + let line = lines[i]; + let trimmed = line.trim(); + + // Block-Ende erkennen mit /& + 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; + const fullHeader = line.substring(1).trim(); + const spaceIndex = fullHeader.indexOf(' '); + + if (spaceIndex !== -1) { + blockType = fullHeader.substring(0, spaceIndex).toLowerCase(); + blockMeta = fullHeader.substring(spaceIndex).trim(); + } else { + blockType = fullHeader.toLowerCase(); + blockMeta = ""; + } + blockBuffer = []; + continue; + } + + // Überschriften abfangen, um vorherige Fußnoten zu flushen + if (/^([1-6])(x|-)?#\s*/.test(trimmed)) { + let footnoteBlock = this._flushFootnotes(); + if (footnoteBlock) result.push(footnoteBlock); + } + + // Freie Linien und Listen-Strukturen + if (trimmed === '___') { + result.push('
${intro}
\n`; + } + tocWrapper += 'STRENG_GEHEIMER_TOC_PLATZHALTER\n'; + tocWrapper += '${escapedCode}`;
+
+ case 'q':
+ const qContent = lines.map(function(l) { return self._parseInline(l); }).join('${qContent}`; + + case 'b': + const bContent = lines.map(function(l) { return self._parseInline(l); }).join('
${fContent}
\n| ${parsedCell} | \n`; + cellIndex++; + if (cellIndex === currentConfiguredCols && i < rawCells.length - 1) { + tableHtml += '
" + pContent + "
"); + paragraphBuffer = []; + } + } + + for (let i = 0; i < elements.length; i++) { + let element = elements[i]; + if (!element) continue; + + let isUlItem = element.startsWith("|
||
+
+
+
+
+ SimonUp – Live Playground
+
+
+
+
+
+
+ SimonUp Playground
+ Die moderne Fluss- & Block-Auszeichnungssprache
+
+
+
+
+
+ SimonUp Input (.up)
+
+
+
+
+ HTML Vorschau (Live)
+
+
+
+
+
+
+
+
\ No newline at end of file