You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
551 B
22 lines
551 B
const { inspect } = require("util");
|
|
const nodeTypes = {
|
|
bold: "**",
|
|
italics: "_",
|
|
strikethrough: "~~",
|
|
underline: "==",
|
|
text: "",
|
|
};
|
|
|
|
const CompileASTtoMarkdown = ast =>
|
|
ast.reduce((acc, value) => {
|
|
if (typeof value === "string") return acc + value;
|
|
if (value.type === "url") {
|
|
return acc + `[${CompileASTtoMarkdown(value.children)}](${value.url})`;
|
|
}
|
|
let str = nodeTypes[value.type];
|
|
str += CompileASTtoMarkdown(value.children);
|
|
str += nodeTypes[value.type];
|
|
return acc + str;
|
|
}, "");
|
|
|
|
module.exports = CompileASTtoMarkdown;
|
|
|