@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
52 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.codeBlock = codeBlock;
exports.codeInline = codeInline;
exports.jsonWithLimit = jsonWithLimit;
const json_1 = require("../../util/json");
const environment_1 = require("../../dataflow/environments/environment");
/**
* Produces a code block in markdown format.
* @example
* ```typescript
* codeBlock('ts', 'const x = 42;');
* // Produces:
* //
* // ```ts
* // const x = 42;
* // ```
* ```
*/
function codeBlock(language, code) {
return `\n\`\`\`${language}\n${code?.trimEnd() ?? ''}\n\`\`\`\n`;
}
/**
* Produces an inline code span in markdown format.
* @example
* ```typescript
* codeInline('const x = 42;');
* // Produces: `<code>const x = 42;</code>`
* ```
*/
function codeInline(code) {
return `<code>${code}</code>`;
}
/**
* Produces a JSON code block in markdown format, with optional length limit.
* If the pretty-printed JSON exceeds the limit, a message is shown instead of the full JSON.
*/
function jsonWithLimit(object, maxLength = 5_000, tooLongText = '_As the code is pretty long, we inhibit pretty printing and syntax highlighting (JSON, hiding built-in):_') {
const prettyPrinted = JSON.stringify(object, json_1.jsonReplacer, 2);
return `
${prettyPrinted.length > maxLength ? tooLongText : ''}
${codeBlock(prettyPrinted.length > maxLength ? 'text' : 'json', prettyPrinted.length > 5_000 ? JSON.stringify(object, (k, v) => {
if (typeof v === 'object' && v !== null && 'id' in v && v['id'] === 0 && 'memory' in v && v['memory']) {
return '<BuiltInEnvironment>';
}
else {
return (0, environment_1.builtInEnvJsonReplacer)(k, v);
}
}) : prettyPrinted)}
`;
}
//# sourceMappingURL=doc-code.js.map