Add responsive iframe support to markdown renderer

This commit is contained in:
Eric Jinks 2018-04-18 14:47:28 +10:00
parent b57f0b0cf1
commit 795159f4b2
3 changed files with 32 additions and 1 deletions

View file

@ -11,6 +11,10 @@ section1: |-
[Link test](/images/uploads/isabella juskova.jpg)
### Embed Test
<iframe width="560" height="315" src="https://www.youtube.com/embed/Js00yn142ic" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
section2: >-
## This is a Container component

View file

@ -6,3 +6,20 @@
max-width: 100%;
height: auto;
}
.Content--Iframe {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
height: auto;
}
.Content--Iframe iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

View file

@ -18,7 +18,8 @@ export default ({ source, className = '' }) => (
className={`Content ${className}`}
source={encodeMarkdownURIs(source)}
renderers={{
image: ImageWithSrcset
image: ImageWithSrcset,
html: HtmlBlock
}}
/>
)
@ -35,3 +36,12 @@ const ImageWithSrcset = ({ nodeKey, src, alt, ...props }) => {
/>
)
}
const HtmlBlock = ({ value }) => (
<div
className={value.indexOf('iframe') ? `Content--Iframe` : ``}
dangerouslySetInnerHTML={{
__html: value
}}
/>
)