const NEW_LINE_EXP = /\n(?!$)/g; /** * @param highlightedCode - A string with new line breaks; the line numbers will be added before each line. * @param start - The number to start the line numbering from; default is 1 * @returns A string with line numbers added before each line */ export function addLineNumbers(highlightedCode: string, start = 1): string { const codeLines = highlightedCode.split(NEW_LINE_EXP); return codeLines .map((line, i) => { return `${line}`; }) .join('\n'); }