UNPKG

gatsby-source-roamresearch

Version:

Source plugin for pulling data into Gatsby from Roam Research

28 lines (27 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeMarkdown = exports.makeMarkdownForBlock = void 0; function replaceSpecialCharacter(string) { return string.replace(/</g, "&#x3C;").replace(/>/g, "&#x3E;"); } const makeMarkdownForBlock = (block, indent = "") => { var _a; let res = replaceSpecialCharacter(block.string); (_a = block.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => { const resForBlock = exports.makeMarkdownForBlock(child, `${indent} `); res += `\n${indent} - ${resForBlock}`; }); return res; }; exports.makeMarkdownForBlock = makeMarkdownForBlock; const makeMarkdown = (page) => { var _a; const value = "title" in page ? page.title : page.string; let res = `# ${replaceSpecialCharacter(value)}`; (_a = page.children) === null || _a === void 0 ? void 0 : _a.forEach((block) => { const resForBlock = exports.makeMarkdownForBlock(block); res += `\n- ${resForBlock}`; }); return res; }; exports.makeMarkdown = makeMarkdown;