mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
added image-replacer (#273)
added image-replacer this component replaces all `<img>`'s in the markdown-it output with an ImageFrame component. This enables us to implement image proxies and other per image customization in the future. 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:
parent
0a48fd0aa5
commit
1db1bcf248
3 changed files with 28 additions and 0 deletions
|
@ -38,6 +38,7 @@ import { replaceYouTubeLink } from './regex-plugins/replace-youtube-link'
|
||||||
import { ComponentReplacer, SubNodeConverter } from './replace-components/ComponentReplacer'
|
import { ComponentReplacer, SubNodeConverter } from './replace-components/ComponentReplacer'
|
||||||
import { GistReplacer } from './replace-components/gist/gist-replacer'
|
import { GistReplacer } from './replace-components/gist/gist-replacer'
|
||||||
import { HighlightedCodeReplacer } from './replace-components/highlighted-fence/highlighted-fence-replacer'
|
import { HighlightedCodeReplacer } from './replace-components/highlighted-fence/highlighted-fence-replacer'
|
||||||
|
import { ImageReplacer } from './replace-components/image/image-replacer'
|
||||||
import { MathjaxReplacer } from './replace-components/mathjax/mathjax-replacer'
|
import { MathjaxReplacer } from './replace-components/mathjax/mathjax-replacer'
|
||||||
import { PdfReplacer } from './replace-components/pdf/pdf-replacer'
|
import { PdfReplacer } from './replace-components/pdf/pdf-replacer'
|
||||||
import { QuoteOptionsReplacer } from './replace-components/quote-options/quote-options-replacer'
|
import { QuoteOptionsReplacer } from './replace-components/quote-options/quote-options-replacer'
|
||||||
|
@ -123,6 +124,7 @@ const MarkdownRenderer: React.FC<MarkdownPreviewProps> = ({ content }) => {
|
||||||
new YoutubeReplacer(),
|
new YoutubeReplacer(),
|
||||||
new VimeoReplacer(),
|
new VimeoReplacer(),
|
||||||
new PdfReplacer(),
|
new PdfReplacer(),
|
||||||
|
new ImageReplacer(),
|
||||||
new TocReplacer(),
|
new TocReplacer(),
|
||||||
new HighlightedCodeReplacer(),
|
new HighlightedCodeReplacer(),
|
||||||
new QuoteOptionsReplacer(),
|
new QuoteOptionsReplacer(),
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export const ImageFrame: React.FC<React.ImgHTMLAttributes<HTMLImageElement>> = ({alt, ...props}) => {
|
||||||
|
return (
|
||||||
|
<img alt={alt} {...props}/>
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { DomElement } from 'domhandler'
|
||||||
|
import React from 'react'
|
||||||
|
import { ComponentReplacer } from '../ComponentReplacer'
|
||||||
|
import { ImageFrame } from './image-frame'
|
||||||
|
|
||||||
|
export class ImageReplacer implements ComponentReplacer {
|
||||||
|
getReplacement (node: DomElement): React.ReactElement | undefined {
|
||||||
|
if (node.name === 'img' && node.attribs) {
|
||||||
|
return <ImageFrame
|
||||||
|
id={node.attribs.id}
|
||||||
|
className={node.attribs.class}
|
||||||
|
src={node.attribs.src}
|
||||||
|
alt={node.attribs.alt}
|
||||||
|
width={node.attribs.width}
|
||||||
|
height={node.attribs.height}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue