Files
site/node_modules/mdast-util-to-markdown/lib/util/indent-lines.js
T
site-admin 3ac81d5a52
deploy / build-and-publish (push) Successful in 1m37s
the editable site (validation-lab)
2026-11-21 08:03:55 +01:00

41 lines
684 B
JavaScript

/**
* @import {IndentLines} from '../types.js'
*/
const eol = /\r?\n|\r/g
/**
* Indents each line.
*
* @type {IndentLines}
*/
export function indentLines(value, map) {
/** @type {Array<string>} */
const result = []
let start = 0
let line = 0
/** @type {RegExpExecArray | null} */
let match
while ((match = eol.exec(value))) {
one(value.slice(start, match.index))
result.push(match[0])
start = match.index + match[0].length
line++
}
one(value.slice(start))
return result.join('')
/**
* Indents a single line.
*
* @param {string} value
* Line.
*/
function one(value) {
result.push(map(value, line, !value))
}
}