Last active
September 6, 2019 16:47
-
-
Save developit/5e1d781516e21d2fe3879499d5b51b9f to your computer and use it in GitHub Desktop.
glitch fix for components/text/markdown.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Markdown Component | |
*/ | |
const Markdown = React.memo(({ children, length, allowImages, renderAsPlaintext, linkifyHeadings }) => { | |
let rendered = md({ allowImages, linkifyHeadings }).render(children || ''); | |
let className = styles.markdownContent; | |
if (length > 0) { | |
rendered = truncate(rendered, length, { ellipsis: '…' }); | |
} | |
if (renderAsPlaintext) { | |
rendered = stripHtml(rendered); | |
className = ''; | |
// in many cases we use the renderAsPlaintext prop to put markdown in a paragraph | |
// <div> can't be a descendant of a <p>, so use span | |
return <span className={className}>{rendered}</span>; | |
} | |
// use <div> here, because <p> and other markup can't be a descendant of a <span> | |
return ( | |
<div | |
className={className} | |
dangerouslySetInnerHTML={{ __html: rendered }} // eslint-disable-line react/no-danger | |
/> | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment