ts-markdown-builder
Version:
Elegant markdown builder with minimal bundle size.
34 lines (33 loc) • 865 B
JavaScript
exports.escape = escape;
exports.joinBlocks = joinBlocks;
exports.maxBackticks = maxBackticks;
exports.prefixLines = prefixLines;
function joinBlocks(blocks) {
blocks = typeof blocks === 'string' ? [blocks] : blocks;
return blocks.map(trimBlock).filter(Boolean).join('\n\n');
}
function trimBlock(block) {
return block.replace(/^\n+|\n+$/g, '');
}
function prefixLines(text, prefix) {
const lines = text.split('\n');
return lines.map(line => `${prefix}${line}`).join('\n');
}
function escape(text) {
return text.replace(/([\\`*_{}[\]()#+\-.!|<>])/g, '\\$1');
}
function maxBackticks(text) {
let max = 0;
let current = 0;
for (let i = 0; i < text.length; i++) {
if (text[i] === '`') {
current++;
max = Math.max(max, current);
} else {
current = 0;
}
}
return max;
}
//# sourceMappingURL=utils.js.map
;