Nested processing for paragraphs
This commit is contained in:
38
markdown.js
38
markdown.js
@@ -164,19 +164,14 @@ class Paragraph extends Symbol {
|
||||
* @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 `<p>${this.lines.join("")}</p>`;
|
||||
return `<p>${this.children.map((c) => c.render()).join("")}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +746,23 @@ const getAmountOfTokenInBeginningOfFile = (token, string) => {
|
||||
/**
|
||||
* @type {Symbol[]}
|
||||
*/
|
||||
const Factories = [
|
||||
const AllSymbols = [
|
||||
Paragraph,
|
||||
Heading,
|
||||
UnorderedListItem,
|
||||
OrderedListItem,
|
||||
Bold,
|
||||
Italic,
|
||||
ImageLink,
|
||||
Link,
|
||||
MultiLineCode,
|
||||
SingleLineCode,
|
||||
Text,
|
||||
];
|
||||
/**
|
||||
* @type {Symbol[]}
|
||||
*/
|
||||
const AllSymbolsExceptParagraph = [
|
||||
Paragraph,
|
||||
Heading,
|
||||
UnorderedListItem,
|
||||
@@ -764,7 +775,6 @@ const Factories = [
|
||||
SingleLineCode,
|
||||
Text,
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} markdown
|
||||
@@ -774,11 +784,8 @@ 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);
|
||||
console.log("starting processing");
|
||||
symbols.forEach((s) => s.process(assetDirectory));
|
||||
|
||||
const html = symbols.map((s) => s.render()).join("");
|
||||
return `<div>${html}</div>`;
|
||||
@@ -788,15 +795,16 @@ export const toHtml = (markdown, assetDirectory) => {
|
||||
*
|
||||
* @param {string} markdown
|
||||
* @param {string} assetDirectory
|
||||
* @param {Symbol[]} allowedSymbols
|
||||
* @returns {Symbol[]}
|
||||
*/
|
||||
const toSymbols = (markdown, assetDirectory) => {
|
||||
const toSymbols = (markdown, assetDirectory, allowedSymbols) => {
|
||||
const lineFeed = new LineFeed(markdown);
|
||||
const symbols = [];
|
||||
|
||||
while (!lineFeed.isEmpty()) {
|
||||
const line = lineFeed.peek();
|
||||
const factory = Factories.find((factory) => factory.canParse(line));
|
||||
const factory = AllSymbols.find((factory) => factory.canParse(line));
|
||||
const symbol = factory.create(lineFeed, assetDirectory);
|
||||
symbols.push(symbol);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user