UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

89 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Mermaid = void 0; const url_encoding_1 = require("../text/url-encoding"); /** * Global mermaid helper object with useful functions. */ exports.Mermaid = { name: 'Mermaid', /** * Replacements applied by escape functions! */ replacements: { // keep newlines '\\n': '\n', '`': '#96;', '[': '#91;', ']': '#93;', '<': '#60;', '>': '#62;', '*': '#42;', '+': '#43;', '-': '#45;', '"': '#34;', '\\': '#92;', '_': '#95;', '{': '#123;', '}': '#125;', '&': '#38;', '\'': '#39;', ':': '#58;', '∨': '#8744;', '∧': '#8743;', '¬': '#172;', '→': '#8594;', '↔': '#8596;', '⇒': '#8658;', '⇔': '#8660;', '∀': '#8704;', '∃': '#8707;', '∈': '#8712;', '∉': '#8713;', '∋': '#8715;', '∌': '#8716;', '∩': '#8745;', '∪': '#8746;', '∫': '#8747;', '⊕': '#8853;', }, /** * Escapes markdown special characters in a string. */ escape(text) { for (const [key, value] of Object.entries(exports.Mermaid.replacements)) { text = text.replaceAll(key, value); } return text; }, /** * Reserved mermaid flowchart keywords that break parsing when used as a bare node id token. */ reservedIds: new Set([ 'graph', 'flowchart', 'subgraph', 'end', 'style', 'default', 'linkStyle', 'interpolate', 'classDef', 'class', 'href', 'click', 'call', 'direction' ]), /** * Escapes a string or number to be used as a mermaid node id. */ escapeId(text) { text = String(text).replace(/[^a-zA-Z0-9:\-./]/g, '_'); return text.replace(/(^|[:\-./])([a-zA-Z0-9_]+)/g, (_m, sep, tok) => sep + (exports.Mermaid.reservedIds.has(tok) ? tok + '_' : tok)); }, /** * Converts mermaid code (potentially produced by {@link DataflowMermaid.convert}) to an url that presents the graph in the mermaid editor. * @param code - code to convert * @param edit - if true, the url will point to the editor, otherwise it will point to the viewer */ codeToUrl(code, edit = false) { const obj = { code, mermaid: { autoSync: true } }; /* `btoa` rather than a `Buffer`, so the pages flowR ships can build this url as well */ return `https://mermaid.live/${edit ? 'edit' : 'view'}#base64:${(0, url_encoding_1.toBase64)(new TextEncoder().encode(JSON.stringify(obj)))}`; } }; //# sourceMappingURL=mermaid.js.map