From 54d016719fa85c8f3744ede656cb5ac9c70e8d90 Mon Sep 17 00:00:00 2001 From: wholteza Date: Sun, 17 Sep 2023 11:16:08 +0200 Subject: [PATCH] WIP paragraphs now claim everything within newlines --- build.js | 1 - markdown.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/build.js b/build.js index 11afbc6..3261654 100644 --- a/build.js +++ b/build.js @@ -49,7 +49,6 @@ manifest.forEach((m) => { if (!fs.existsSync(m.assetDirectoryPath)) return; const assetsList = fs.readdirSync(m.assetDirectoryPath); - console.log(assetsList); assetsList.forEach((assetName) => fs.cpSync( `${m.assetDirectoryPath}/${assetName}`, diff --git a/markdown.js b/markdown.js index 0ef3d26..3359016 100644 --- a/markdown.js +++ b/markdown.js @@ -99,6 +99,49 @@ class Heading extends Symbol { } } +class Paragraph extends Symbol { + /** + * @type {string[]} + */ + lines = []; + /** + * + * @param {string} line + * @returns {boolean} + */ + static canParse(line) { + return line === ""; + } + + /** + * + * @param {LineFeed} lineFeed + * @returns {Symbol} + */ + static create(lineFeed) { + const instance = new Paragraph(); + lineFeed.claim(); + + const lines = []; + let endOfParagraph = false; + while (!endOfParagraph && !lineFeed.isEmpty()) { + const line = lineFeed.peek(); + if (line === "") { + endOfParagraph = true; + continue; + } + lines.push(lineFeed.claim()); + } + + instance.lines = lines; + return instance; + } + + render() { + return `

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

`; + } +} + class UnorderedListItem extends Symbol { /** * @type {string} @@ -585,6 +628,7 @@ const getAmountOfTokenInBeginningOfFile = (token, string) => { * @type {Symbol[]} */ const Factories = [ + Paragraph, Heading, UnorderedListItem, OrderedListItem,