UNPKG

@redocly/theme

Version:

Shared UI components lib

18 lines 725 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addLineNumbers = addLineNumbers; 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 */ function addLineNumbers(highlightedCode, start = 1) { const codeLines = highlightedCode.split(NEW_LINE_EXP); return codeLines .map((line, i) => { return `<span class='line' data-line-number='${start + i}'>${line}</span>`; }) .join('\n'); } //# sourceMappingURL=add-line-numbers.js.map