Add optional src prop to <Content /> component

This commit is contained in:
Eric Jinks 2018-05-03 13:18:38 +10:00
parent 755d1c325d
commit 884534c685

View file

@ -1,5 +1,6 @@
import React from 'react'
import Marked from 'react-markdown'
import PropTypes from 'prop-types'
import { getImageSrc, getImageSrcset } from '../util/getImageUrl'
import './Content.css'
@ -13,17 +14,6 @@ const encodeMarkdownURIs = (source = '') => {
})
}
export default ({ source, className = '' }) => (
<Marked
className={`Content ${className}`}
source={encodeMarkdownURIs(source)}
renderers={{
image: ImageWithSrcset,
html: HtmlBlock
}}
/>
)
const ImageWithSrcset = ({ nodeKey, src, alt, ...props }) => {
const decodedSrc = decodeURI(src)
return (
@ -48,3 +38,22 @@ const HtmlBlock = ({ value }) => {
/>
)
}
const Content = ({ source, src, className = '' }) => (
<Marked
className={`Content ${className}`}
source={encodeMarkdownURIs(source || src)}
renderers={{
image: ImageWithSrcset,
html: HtmlBlock
}}
/>
)
Content.propTypes = {
source: PropTypes.string,
src: PropTypes.string,
className: PropTypes.string
}
export default Content