mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 10:15:17 -04:00
22 lines
756 B
TypeScript
22 lines
756 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { DomElement } from 'domhandler'
|
|
import React from 'react'
|
|
import { ComponentReplacer } from '../ComponentReplacer'
|
|
import { VegaChart } from './vega-chart'
|
|
|
|
export class VegaReplacer implements ComponentReplacer {
|
|
getReplacement(codeNode: DomElement): React.ReactElement | undefined {
|
|
if (codeNode.name !== 'code' || !codeNode.attribs || !codeNode.attribs['data-highlight-language'] || codeNode.attribs['data-highlight-language'] !== 'vega-lite' || !codeNode.children || !codeNode.children[0]) {
|
|
return
|
|
}
|
|
|
|
const code = codeNode.children[0].data as string
|
|
|
|
return <VegaChart code={ code }/>
|
|
}
|
|
}
|