Add optional src prop to <Content /> component
This commit is contained in:
parent
755d1c325d
commit
884534c685
1 changed files with 20 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue