wip
This commit is contained in:
137
markdown.js
137
markdown.js
@@ -56,6 +56,14 @@ class Symbol {
|
|||||||
static create(lineFeed, assetDirectory) {
|
static create(lineFeed, assetDirectory) {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
throw new Error("Not Implemented");
|
||||||
|
}
|
||||||
render() {
|
render() {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
@@ -94,6 +102,15 @@ class Heading extends Symbol {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<h${this.level}>${this.text}</h${this.level}>`;
|
return `<h${this.level}>${this.text}</h${this.level}>`;
|
||||||
}
|
}
|
||||||
@@ -104,6 +121,10 @@ class Paragraph extends Symbol {
|
|||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
*/
|
*/
|
||||||
lines = [];
|
lines = [];
|
||||||
|
/**
|
||||||
|
* @type {Symbol[]}
|
||||||
|
*/
|
||||||
|
children = [];
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {string} line
|
* @param {string} line
|
||||||
@@ -137,6 +158,23 @@ class Paragraph extends Symbol {
|
|||||||
return instance;
|
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() {
|
render() {
|
||||||
return `<p>${this.lines.join("")}</p>`;
|
return `<p>${this.lines.join("")}</p>`;
|
||||||
}
|
}
|
||||||
@@ -173,6 +211,15 @@ class UnorderedListItem extends Symbol {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<li class="indent-${this.level}">${this.text} indentation level ${this.level}</li>`;
|
return `<li class="indent-${this.level}">${this.text} indentation level ${this.level}</li>`;
|
||||||
}
|
}
|
||||||
@@ -209,6 +256,15 @@ class OrderedListItem extends Symbol {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<li class="indent-${this.level}">${this.text} indentation level ${this.level}</li>`;
|
return `<li class="indent-${this.level}">${this.text} indentation level ${this.level}</li>`;
|
||||||
}
|
}
|
||||||
@@ -255,6 +311,15 @@ class Link extends Symbol {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<a href="${this.link}">${this.text}</a>`;
|
return `<a href="${this.link}">${this.text}</a>`;
|
||||||
}
|
}
|
||||||
@@ -311,6 +376,15 @@ class ImageLink extends Symbol {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<img src="${this.link}" alt="${this.alt}"/>`;
|
return `<img src="${this.link}" alt="${this.alt}"/>`;
|
||||||
}
|
}
|
||||||
@@ -359,6 +433,16 @@ class Italic extends Symbol {
|
|||||||
instance.text = lineWithoutUnderscores;
|
instance.text = lineWithoutUnderscores;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<i>${this.text}</i>`;
|
return `<i>${this.text}</i>`;
|
||||||
}
|
}
|
||||||
@@ -407,6 +491,16 @@ class Bold extends Symbol {
|
|||||||
instance.text = lineWithoutUnderscores;
|
instance.text = lineWithoutUnderscores;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<b>${this.text}</b>`;
|
return `<b>${this.text}</b>`;
|
||||||
}
|
}
|
||||||
@@ -455,6 +549,16 @@ class SingleLineCode extends Symbol {
|
|||||||
instance.text = lineWithoutUnderscores;
|
instance.text = lineWithoutUnderscores;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<code>${this.text}</code>`;
|
return `<code>${this.text}</code>`;
|
||||||
}
|
}
|
||||||
@@ -522,12 +626,22 @@ class MultiLineCode extends Symbol {
|
|||||||
instance.text = lines.join("\n");
|
instance.text = lines.join("\n");
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<pre><code>${this.text}</code></pre>`;
|
return `<pre><code>${this.text}</code></pre>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CatchAll extends Symbol {
|
class Text extends Symbol {
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
@@ -547,10 +661,20 @@ class CatchAll extends Symbol {
|
|||||||
* @returns {Symbol}
|
* @returns {Symbol}
|
||||||
*/
|
*/
|
||||||
static create(lineFeed) {
|
static create(lineFeed) {
|
||||||
const instance = new CatchAll();
|
const instance = new Text();
|
||||||
instance.text = lineFeed.claim();
|
instance.text = lineFeed.claim();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} assetDirectory
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
process(assetDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return `<span>${this.text}</span>`;
|
return `<span>${this.text}</span>`;
|
||||||
}
|
}
|
||||||
@@ -638,7 +762,7 @@ const Factories = [
|
|||||||
Link,
|
Link,
|
||||||
MultiLineCode,
|
MultiLineCode,
|
||||||
SingleLineCode,
|
SingleLineCode,
|
||||||
CatchAll,
|
Text,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -649,6 +773,13 @@ const Factories = [
|
|||||||
*/
|
*/
|
||||||
export const toHtml = (markdown, assetDirectory) => {
|
export const toHtml = (markdown, assetDirectory) => {
|
||||||
const symbols = toSymbols(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("");
|
const html = symbols.map((s) => s.render()).join("");
|
||||||
return `<div>${html}</div>`;
|
return `<div>${html}</div>`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,3 +74,7 @@ const y = () => {
|
|||||||
[link to the index](https://blog.zacke.dev) with text after it
|
[link to the index](https://blog.zacke.dev) with text after it
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
rstd
|
||||||
|
rastd
|
||||||
|
rstd
|
||||||
|
|||||||
Reference in New Issue
Block a user