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:
Philip Molares 2020-06-25 22:25:22 +02:00 committed by GitHub
parent 0a48fd0aa5
commit 1db1bcf248
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -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}
/>
}
}
}