mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
Add abcjs (#537)
This commit is contained in:
parent
86e41929ef
commit
119c9512e7
7 changed files with 82 additions and 0 deletions
|
@ -53,6 +53,7 @@ import { replaceQuoteExtraTime } from './regex-plugins/replace-quote-extra-time'
|
|||
import { replaceVimeoLink } from './regex-plugins/replace-vimeo-link'
|
||||
import { replaceYouTubeLink } from './regex-plugins/replace-youtube-link'
|
||||
import { buildTransformer, calculateNewLineNumberMapping, LineKeys } from './renderer-utils'
|
||||
import { AbcReplacer } from './replace-components/abc/abc-replacer'
|
||||
import { AsciinemaReplacer } from './replace-components/asciinema/asciinema-replacer'
|
||||
import { LinemarkerReplacer } from './replace-components/linemarker/linemarker-replacer'
|
||||
import { ComponentReplacer } from './replace-components/ComponentReplacer'
|
||||
|
@ -346,6 +347,7 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({
|
|||
new YoutubeReplacer(),
|
||||
new VimeoReplacer(),
|
||||
new AsciinemaReplacer(),
|
||||
new AbcReplacer(),
|
||||
new PdfReplacer(),
|
||||
new ImageReplacer(),
|
||||
new CsvReplacer(),
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import React, { useEffect, useRef } from 'react'
|
||||
import { renderAbc } from 'abcjs'
|
||||
|
||||
export interface AbcFrameProps {
|
||||
code: string
|
||||
}
|
||||
export const AbcFrame: React.FC<AbcFrameProps> = ({ code }) => {
|
||||
const container = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (container.current) {
|
||||
renderAbc(container.current, code)
|
||||
}
|
||||
}, [code])
|
||||
|
||||
return (
|
||||
<div ref={container}/>
|
||||
)
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import { DomElement } from 'domhandler'
|
||||
import React from 'react'
|
||||
import { ComponentReplacer } from '../ComponentReplacer'
|
||||
import { AbcFrame } from './abc-frame'
|
||||
|
||||
export class AbcReplacer implements ComponentReplacer {
|
||||
getReplacement (codeNode: DomElement, index: number): React.ReactElement | undefined {
|
||||
if (codeNode.name !== 'code' || !codeNode.attribs || !codeNode.attribs['data-highlight-language'] || codeNode.attribs['data-highlight-language'] !== 'abc' || !codeNode.children || !codeNode.children[0]) {
|
||||
return
|
||||
}
|
||||
|
||||
const code = codeNode.children[0].data as string
|
||||
|
||||
return <AbcFrame key={'index'} code={code}/>
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue