added markmap support to the markdown-renderer (#572)

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
Philip Molares 2020-09-19 20:34:44 +02:00 committed by GitHub
parent 204f2deb5a
commit 005c80ff55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 460 additions and 21 deletions

View file

@ -0,0 +1,25 @@
import { transform } from 'markmap-lib/dist/transform'
import { Markmap } from 'markmap-lib/dist/view'
import React, { useEffect, useRef } from 'react'
export interface MarkmapFrameProps {
code: string
}
export const MarkmapFrame: React.FC<MarkmapFrameProps> = ({ code }) => {
const diagramContainer = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!diagramContainer.current) {
return
}
const svg: SVGSVGElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg.setAttribute('width', '100%')
diagramContainer.current.querySelectorAll('svg').forEach(child => child.remove())
diagramContainer.current.appendChild(svg)
const data = transform(code)
Markmap.create(svg, {}, data)
}, [code])
return <div className={'text-center'} ref={diagramContainer}/>
}