markdown-code-example-inserter
Version:
Syncs code examples with markdown documentation.
18 lines (15 loc) • 392 B
text/typescript
export function fixCodeIndents(rawCode: string, indent: string): string {
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');
}