const { BOLD, TEXT, ITALICS, STRIKETHROUGH, UNDERLINE, URL, } = require("../constants"); function CompileHTML(ast) { let str = "
"; const OpenTags = { bold: () => ``, text: () => ``, italics: () => ``, strikethrough: () => ``, underline: () => ``, url: url => ``, }; const CloseTags = { text: "", bold: "", italics: "", strikethrough: "", underline: "", url: "", }; const mapper = node => { node.forEach(element => { if (typeof element === "string") { str += `${element}`; } else if (typeof element === "object") { str += OpenTags[element.type]("url" in element ? element.url : null); mapper(element.children); str += CloseTags[element.type]; } }); return ""; }; mapper(ast); str += "
"; return str; } module.exports = CompileHTML;