Identifies level 1 headings and selects everything as text for it.
This commit is contained in:
52
markdown.js
52
markdown.js
@@ -1,19 +1,39 @@
|
||||
const toHtml = () => {
|
||||
return `<div>markdown</div>`;
|
||||
export const toHtml = (markdown) => {
|
||||
const symbols = toSymbols(markdown);
|
||||
const html = [];
|
||||
symbols.forEach((s) =>
|
||||
html.push(renderers.find((r) => r.key === s.key).render(s))
|
||||
);
|
||||
|
||||
return `<div>${html.join("\r\n")}</div>`;
|
||||
};
|
||||
|
||||
const singleSymbols = [
|
||||
"#",
|
||||
"##",
|
||||
"###",
|
||||
"####",
|
||||
"#####",
|
||||
"######",
|
||||
"-",
|
||||
"- []",
|
||||
"- [ ]",
|
||||
const toSymbols = (markdown) => {
|
||||
const symbols = [];
|
||||
|
||||
if (heading.symbols.some((s) => markdown.includes(s))) {
|
||||
const symbol = Object.assign({}, heading);
|
||||
symbol.text = markdown;
|
||||
symbols.push(symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
};
|
||||
|
||||
const heading = {
|
||||
key: "heading",
|
||||
level: 1,
|
||||
multiLine: false,
|
||||
symbols: ["#", "##", "###", "####", "#####", "######"],
|
||||
text: "",
|
||||
children: [],
|
||||
};
|
||||
|
||||
const renderers = [
|
||||
{
|
||||
key: "heading",
|
||||
render: (symbol) => {
|
||||
return `<h1>${symbol.text}</h1>`;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const doubleSymbols = ["*", "**", "_", "__", "`", "```"];
|
||||
|
||||
const symbols = {};
|
||||
|
||||
Reference in New Issue
Block a user