WIP paragraphs now claim everything within newlines

This commit is contained in:
2023-09-17 11:16:08 +02:00
parent d8ee8c348c
commit 54d016719f
2 changed files with 44 additions and 1 deletions

View File

@@ -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 `<p>${this.lines.join("")}</p>`;
}
}
class UnorderedListItem extends Symbol {
/**
* @type {string}
@@ -585,6 +628,7 @@ const getAmountOfTokenInBeginningOfFile = (token, string) => {
* @type {Symbol[]}
*/
const Factories = [
Paragraph,
Heading,
UnorderedListItem,
OrderedListItem,