WIP paragraphs now claim everything within newlines
This commit is contained in:
44
markdown.js
44
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 `<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,
|
||||
|
||||
Reference in New Issue
Block a user