mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
markdown-it-configurator (#626)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
89968387c2
commit
0670cddb0b
42 changed files with 524 additions and 360 deletions
|
@ -2,7 +2,7 @@ import equal from 'fast-deep-equal'
|
|||
import { RefObject, useCallback, useEffect, useRef } from 'react'
|
||||
import useResizeObserver from 'use-resize-observer'
|
||||
import { LineMarkerPosition } from '../types'
|
||||
import { LineMarkers } from '../markdown-it-plugins/line-number-marker'
|
||||
import { LineMarkers } from '../replace-components/linemarker/line-number-marker'
|
||||
|
||||
export const calculateLineMarkerPositions = (documentElement: HTMLDivElement, currentLineMarkers: LineMarkers[], offset?: number): LineMarkerPosition[] => {
|
||||
const lineMarkers = currentLineMarkers
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
import equal from 'fast-deep-equal'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { RawYAMLMetadata, YAMLMetaData } from '../../editor/yaml-metadata/yaml-metadata'
|
||||
|
||||
export const usePostMetaDataOnChange = (
|
||||
rawMetaRef: RawYAMLMetadata|undefined,
|
||||
firstHeadingRef: string|undefined,
|
||||
onMetaDataChange?: (yamlMetaData: YAMLMetaData | undefined) => void,
|
||||
onFirstHeadingChange?: (firstHeading: string | undefined) => void
|
||||
): void => {
|
||||
const oldMetaRef = useRef<RawYAMLMetadata>()
|
||||
const oldFirstHeadingRef = useRef<string>()
|
||||
|
||||
useEffect(() => {
|
||||
if (onMetaDataChange && !equal(oldMetaRef.current, rawMetaRef)) {
|
||||
if (rawMetaRef) {
|
||||
const newMetaData = new YAMLMetaData(rawMetaRef)
|
||||
onMetaDataChange(newMetaData)
|
||||
} else {
|
||||
onMetaDataChange(undefined)
|
||||
}
|
||||
oldMetaRef.current = rawMetaRef
|
||||
}
|
||||
if (onFirstHeadingChange && !equal(firstHeadingRef, oldFirstHeadingRef.current)) {
|
||||
onFirstHeadingChange(firstHeadingRef || undefined)
|
||||
oldFirstHeadingRef.current = firstHeadingRef
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
import equal from 'fast-deep-equal'
|
||||
import { RefObject, useEffect, useRef } from 'react'
|
||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
||||
|
||||
export const usePostTocAstOnChange = (tocAst: RefObject<TocAst|undefined>, onTocChange?: (ast: TocAst) => void): void => {
|
||||
const lastTocAst = useRef<TocAst>()
|
||||
useEffect(() => {
|
||||
if (onTocChange && tocAst.current && !equal(tocAst, lastTocAst.current)) {
|
||||
lastTocAst.current = tocAst.current
|
||||
onTocChange(tocAst.current)
|
||||
}
|
||||
}, [onTocChange, tocAst])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue