mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00

Doing this BEFORE the merge prevents a lot of merge conflicts. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
18 lines
610 B
TypeScript
18 lines
610 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
/**
|
|
* Calculates the absolute start position of every line.
|
|
*
|
|
* @param markdownContentLines The lines of the document
|
|
* @returns the calculated line starts
|
|
*/
|
|
export const calculateLineStartIndexes = (markdownContentLines: string[]): number[] => {
|
|
return markdownContentLines.reduce((state, line, lineIndex, lines) => {
|
|
const lastIndex = lineIndex === 0 ? 0 : state[lineIndex - 1] + lines[lineIndex - 1].length + 1
|
|
return [...state, lastIndex]
|
|
}, [] as number[])
|
|
}
|