mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
use types from markdown-it-toc-done-right plugin (#665)
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
63896fac19
commit
c09aaf010c
8 changed files with 7 additions and 45 deletions
|
@ -8,7 +8,7 @@ import React, { RefObject, useState } from 'react'
|
||||||
import { Dropdown } from 'react-bootstrap'
|
import { Dropdown } from 'react-bootstrap'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import useResizeObserver from 'use-resize-observer'
|
import useResizeObserver from 'use-resize-observer'
|
||||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
import { TocAst } from 'markdown-it-toc-done-right'
|
||||||
import { ApplicationState } from '../../../redux'
|
import { ApplicationState } from '../../../redux'
|
||||||
import { ForkAwesomeIcon } from '../../common/fork-awesome/fork-awesome-icon'
|
import { ForkAwesomeIcon } from '../../common/fork-awesome/fork-awesome-icon'
|
||||||
import { ShowIf } from '../../common/show-if/show-if'
|
import { ShowIf } from '../../common/show-if/show-if'
|
||||||
|
|
|
@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import React, { Fragment, ReactElement, useMemo } from 'react'
|
import React, { Fragment, ReactElement, useMemo } from 'react'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
import { TocAst } from 'markdown-it-toc-done-right'
|
||||||
import { ShowIf } from '../../common/show-if/show-if'
|
import { ShowIf } from '../../common/show-if/show-if'
|
||||||
import './table-of-contents.scss'
|
import './table-of-contents.scss'
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import React, { useCallback, useMemo, useRef, useState } from 'react'
|
import React, { useCallback, useMemo, useRef, useState } from 'react'
|
||||||
import { Alert } from 'react-bootstrap'
|
import { Alert } from 'react-bootstrap'
|
||||||
import { Trans } from 'react-i18next'
|
import { Trans } from 'react-i18next'
|
||||||
import { TocAst } from '../../external-types/markdown-it-toc-done-right/interface'
|
import { TocAst } from 'markdown-it-toc-done-right'
|
||||||
import { InternalLink } from '../common/links/internal-link'
|
import { InternalLink } from '../common/links/internal-link'
|
||||||
import { ShowIf } from '../common/show-if/show-if'
|
import { ShowIf } from '../common/show-if/show-if'
|
||||||
import { RawYAMLMetadata, YAMLMetaData } from '../editor/yaml-metadata/yaml-metadata'
|
import { RawYAMLMetadata, YAMLMetaData } from '../editor/yaml-metadata/yaml-metadata'
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import equal from 'fast-deep-equal'
|
import equal from 'fast-deep-equal'
|
||||||
import { RefObject, useEffect, useRef } from 'react'
|
import { RefObject, useEffect, useRef } from 'react'
|
||||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
import { TocAst } from 'markdown-it-toc-done-right'
|
||||||
|
|
||||||
export const usePostTocAstOnChange = (tocAst: RefObject<TocAst|undefined>, onTocChange?: (ast: TocAst) => void): void => {
|
export const usePostTocAstOnChange = (tocAst: RefObject<TocAst|undefined>, onTocChange?: (ast: TocAst) => void): void => {
|
||||||
const lastTocAst = useRef<TocAst>()
|
const lastTocAst = useRef<TocAst>()
|
||||||
|
|
|
@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
import { TocAst } from 'markdown-it-toc-done-right'
|
||||||
import { RawYAMLMetadata } from '../../editor/yaml-metadata/yaml-metadata'
|
import { RawYAMLMetadata } from '../../editor/yaml-metadata/yaml-metadata'
|
||||||
import { documentToc } from '../markdown-it-plugins/document-toc'
|
import { documentToc } from '../markdown-it-plugins/document-toc'
|
||||||
import { frontmatterExtract } from '../markdown-it-plugins/frontmatter'
|
import { frontmatterExtract } from '../markdown-it-plugins/frontmatter'
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import toc from 'markdown-it-toc-done-right'
|
import toc, { TocAst } from 'markdown-it-toc-done-right'
|
||||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
|
||||||
import { slugify } from '../../editor/table-of-contents/table-of-contents'
|
import { slugify } from '../../editor/table-of-contents/table-of-contents'
|
||||||
|
|
||||||
export type DocumentTocPluginOptions = (ast: TocAst) => void
|
export type DocumentTocPluginOptions = (ast: TocAst) => void
|
||||||
|
|
||||||
export const documentToc:MarkdownIt.PluginWithOptions<DocumentTocPluginOptions> = (markdownIt, onToc) => {
|
export const documentToc: MarkdownIt.PluginWithOptions<DocumentTocPluginOptions> = (markdownIt, onToc) => {
|
||||||
if (!onToc) {
|
if (!onToc) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare module 'markdown-it-toc-done-right' {
|
|
||||||
import MarkdownIt from 'markdown-it/lib'
|
|
||||||
import { TocOptions } from './interface'
|
|
||||||
const markdownItTocDoneRight: MarkdownIt.PluginWithOptions<TocOptions>
|
|
||||||
export = markdownItTocDoneRight
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface TocOptions {
|
|
||||||
placeholder: string
|
|
||||||
slugify: (s: string) => string
|
|
||||||
containerClass: string
|
|
||||||
containerId: string
|
|
||||||
listClass: string
|
|
||||||
itemClass: string
|
|
||||||
linkClass: string
|
|
||||||
level: number | number[]
|
|
||||||
listType: 'ol' | 'ul'
|
|
||||||
format: (s: string) => string
|
|
||||||
callback: (tocCode: string, ast: TocAst) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TocAst {
|
|
||||||
l: number
|
|
||||||
n: string
|
|
||||||
c: TocAst[]
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue