From 04c1e12ed5c392b84136cbf9e93f49283dee27c7 Mon Sep 17 00:00:00 2001 From: wholteza Date: Mon, 18 Sep 2023 12:32:30 +0200 Subject: [PATCH] wip --- markdown.js | 137 ++++++++++++++++++++++++++++++++- notes/1-initial-commit/note.md | 4 + 2 files changed, 138 insertions(+), 3 deletions(-) diff --git a/markdown.js b/markdown.js index 3359016..73a9b51 100644 --- a/markdown.js +++ b/markdown.js @@ -56,6 +56,14 @@ class Symbol { static create(lineFeed, assetDirectory) { throw new Error("Not implemented"); } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + throw new Error("Not Implemented"); + } render() { throw new Error("Not implemented"); } @@ -94,6 +102,15 @@ class Heading extends Symbol { return instance; } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.text}`; } @@ -104,6 +121,10 @@ class Paragraph extends Symbol { * @type {string[]} */ lines = []; + /** + * @type {Symbol[]} + */ + children = []; /** * * @param {string} line @@ -137,6 +158,23 @@ class Paragraph extends Symbol { return instance; } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + if (this.lines.length === 0) return; + const symbols = toSymbols(this.lines.join("\n"), assetDirectory); + const lastIterationSymbolsAsJson = JSON.stringify(symbols); + // do { + // symbols.forEach((s) => s.process()); + // } while (JSON.stringify(symbols) !== lastIterationSymbolsAsJson); + this.lines = []; + this.children = symbols; + } + render() { return `

${this.lines.join("")}

`; } @@ -173,6 +211,15 @@ class UnorderedListItem extends Symbol { return instance; } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `
  • ${this.text} indentation level ${this.level}
  • `; } @@ -209,6 +256,15 @@ class OrderedListItem extends Symbol { return instance; } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `
  • ${this.text} indentation level ${this.level}
  • `; } @@ -255,6 +311,15 @@ class Link extends Symbol { return instance; } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.text}`; } @@ -311,6 +376,15 @@ class ImageLink extends Symbol { return instance; } + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.alt}`; } @@ -359,6 +433,16 @@ class Italic extends Symbol { instance.text = lineWithoutUnderscores; return instance; } + + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.text}`; } @@ -407,6 +491,16 @@ class Bold extends Symbol { instance.text = lineWithoutUnderscores; return instance; } + + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.text}`; } @@ -455,6 +549,16 @@ class SingleLineCode extends Symbol { instance.text = lineWithoutUnderscores; return instance; } + + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.text}`; } @@ -522,12 +626,22 @@ class MultiLineCode extends Symbol { instance.text = lines.join("\n"); return instance; } + + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `
    ${this.text}
    `; } } -class CatchAll extends Symbol { +class Text extends Symbol { /** * @type {string} */ @@ -547,10 +661,20 @@ class CatchAll extends Symbol { * @returns {Symbol} */ static create(lineFeed) { - const instance = new CatchAll(); + const instance = new Text(); instance.text = lineFeed.claim(); return instance; } + + /** + * + * @param {string} assetDirectory + * @returns {void} + */ + process(assetDirectory) { + return; + } + render() { return `${this.text}`; } @@ -638,7 +762,7 @@ const Factories = [ Link, MultiLineCode, SingleLineCode, - CatchAll, + Text, ]; /** @@ -649,6 +773,13 @@ const Factories = [ */ export const toHtml = (markdown, assetDirectory) => { const symbols = toSymbols(markdown, assetDirectory); + + let lastIterationsSymbolsAsJson = JSON.stringify(symbols); + do { + console.log("starting processing"); + symbols.forEach((s) => s.process(assetDirectory)); + } while (JSON.stringify(symbols) !== lastIterationsSymbolsAsJson); + const html = symbols.map((s) => s.render()).join(""); return `
    ${html}
    `; }; diff --git a/notes/1-initial-commit/note.md b/notes/1-initial-commit/note.md index d037554..ababd3b 100644 --- a/notes/1-initial-commit/note.md +++ b/notes/1-initial-commit/note.md @@ -74,3 +74,7 @@ const y = () => { [link to the index](https://blog.zacke.dev) with text after it ![alt-text](@asset/git.png) + +rstd +rastd +rstd