UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

63 lines (61 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.details = details; exports.block = block; exports.section = section; exports.collapsibleToc = collapsibleToc; const doc_general_1 = require("./doc-general"); const strings_1 = require("../../util/text/strings"); const mermaid_1 = require("../../util/mermaid/mermaid"); /** * */ function details(title, content, { color, open = false, hideIfEmpty = true, prefixInit = '' } = {}) { return hideIfEmpty && content.trim().length === 0 ? '' : ` ${prefixInit}<details${open ? ' open' : ''}><summary${color ? ' style="color:' + color + '"' : ''}>${title}</summary> ${content} ${prefixInit}</details> `; } /** * */ function block({ type, content }) { return ` > [!${type}] ${(0, doc_general_1.prefixLines)(content, '> ')} `; } /** * */ function section(title, depth = 2, anchor = mermaid_1.Mermaid.escapeId(title)) { return `<h${depth} id="${anchor}">${title}</h${depth}>`; } function strToLink(str) { const match = str.match(/^(.*?)@(.*)$/); if (match) { const [, name, link] = match; return `[${name}](${link})`; } return `[${str}](#${mermaid_1.Mermaid.escapeId(str)})`; } /** * Supported pattern: `Name@link` */ function collapsibleToc(content) { let output = ''; for (const [section, subsections] of Object.entries(content)) { output += `- ${strToLink(section)}\n`; if (subsections) { for (const [subsection, items] of Object.entries(subsections)) { output += ` - ${strToLink(subsection)} \n`; if (items) { output += ` ${(0, strings_1.joinWithLast)(Object.keys(items).map(strToLink))}\n`; } } } } return output; } //# sourceMappingURL=doc-structure.js.map