UNPKG

markdown-code-example-inserter

Version:
17 lines (16 loc) 374 B
export function fixCodeIndents(rawCode, indent) { const code = rawCode.trim(); if (!indent) { return code; } const lines = code.split('\n'); const indented = lines.map((line) => { if (line.trim()) { return `${indent}${line}`; } else { return ''; } }); return indented.join('\n'); }