mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
Update markmap (#834)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
1f4662838d
commit
c5af44909c
4 changed files with 51 additions and 27 deletions
|
@ -45,17 +45,15 @@ export const MarkmapFrame: React.FC<MarkmapFrameProps> = ({ code }) => {
|
|||
return
|
||||
}
|
||||
const actualContainer = diagramContainer.current
|
||||
Promise.all([import(/* webpackChunkName: "markmap" */ 'markmap-lib'), import(/* webpackChunkName: "markmap" */ 'markmap-view')])
|
||||
.then(([{ transform }, { Markmap }]) => {
|
||||
const svg: SVGSVGElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
||||
svg.setAttribute('width', '100%')
|
||||
actualContainer.querySelectorAll('svg').forEach(child => child.remove())
|
||||
actualContainer.appendChild(svg)
|
||||
const { root } = transform(code)
|
||||
Markmap.create(svg, {}, root)
|
||||
}).catch(() => {
|
||||
console.error('error while loading markmap')
|
||||
})
|
||||
import('./markmap-loader').then(({ markmapLoader }) => {
|
||||
const svg: SVGSVGElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
||||
svg.setAttribute('width', '100%')
|
||||
actualContainer.querySelectorAll('svg').forEach(child => child.remove())
|
||||
actualContainer.appendChild(svg)
|
||||
markmapLoader(svg, code)
|
||||
}).catch(() => {
|
||||
console.error('error while loading markmap')
|
||||
})
|
||||
}, [code])
|
||||
|
||||
return (
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { loadCSS, loadJS } from 'markmap-common'
|
||||
import { Transformer } from 'markmap-lib'
|
||||
import { Markmap } from 'markmap-view'
|
||||
|
||||
const transformer: Transformer = new Transformer()
|
||||
|
||||
export const markmapLoader = (svg: SVGSVGElement, code: string): void => {
|
||||
const { root, features } = transformer.transform(code)
|
||||
const { styles, scripts } = transformer.getUsedAssets(features)
|
||||
|
||||
if (styles) {
|
||||
loadCSS(styles)
|
||||
}
|
||||
if (scripts) {
|
||||
loadJS(scripts).catch(console.log)
|
||||
}
|
||||
|
||||
Markmap.create(svg, {}, root)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue