Skip to content

Instantly share code, notes, and snippets.

@developit
Last active September 6, 2019 16:47
Show Gist options
  • Save developit/5e1d781516e21d2fe3879499d5b51b9f to your computer and use it in GitHub Desktop.
Save developit/5e1d781516e21d2fe3879499d5b51b9f to your computer and use it in GitHub Desktop.
glitch fix for components/text/markdown.js
/**
* 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