hedgedoc/frontend/src/redux/note-details/calculate-line-start-indexes.ts
Tilman Vatteroth 762a0a850e
fix: Move content into to frontend directory
Doing this BEFORE the merge prevents a lot of merge conflicts.

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2022-11-20 19:48:40 +01:00

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[])
}