mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-31 23:28:34 -04:00
Move markdown split into redux (#1681)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
71e668cd17
commit
6594e1bb86
30 changed files with 217 additions and 226 deletions
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useNoteMarkdownContent } from './use-note-markdown-content'
|
||||
import { useApplicationState } from './use-application-state'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
/**
|
||||
* Extracts the markdown content of the current note from the global application state and removes the frontmatter.
|
||||
* @return the markdown content of the note without frontmatter
|
||||
*/
|
||||
export const useNoteMarkdownContentWithoutFrontmatter = (): string => {
|
||||
const markdownContent = useNoteMarkdownContent()
|
||||
const lineOffset = useApplicationState((state) => state.noteDetails.frontmatterRendererInfo.lineOffset)
|
||||
|
||||
return useMemo(() => markdownContent.split('\n').slice(lineOffset).join('\n'), [markdownContent, lineOffset])
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react'
|
||||
import { useApplicationState } from './use-application-state'
|
||||
import { useNoteMarkdownContent } from './use-note-markdown-content'
|
||||
|
||||
export const useTrimmedNoteMarkdownContentWithoutFrontmatter = (): string[] => {
|
||||
const maxLength = useApplicationState((state) => state.config.maxDocumentLength)
|
||||
const markdownContent = useNoteMarkdownContent()
|
||||
const markdownContentLines = useApplicationState((state) => state.noteDetails.markdownContentLines)
|
||||
const lineOffset = useApplicationState((state) => state.noteDetails.frontmatterRendererInfo.lineOffset)
|
||||
|
||||
const trimmedLines = useMemo(() => {
|
||||
if (markdownContent.length > maxLength) {
|
||||
return markdownContent.slice(0, maxLength).split('\n')
|
||||
} else {
|
||||
return markdownContentLines
|
||||
}
|
||||
}, [markdownContent, markdownContentLines, maxLength])
|
||||
|
||||
return useMemo(() => {
|
||||
return trimmedLines.slice(lineOffset)
|
||||
}, [lineOffset, trimmedLines])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue