html renders as string
Closed this issue · 1 comments
dvzrd commented
When I add html inside markdown (sometimes it becomes necessary) it parses as a string wrapped inside a p element.
Any ideas how to get html to render as normal?
dvzrd commented
To anyone having a similar issue. I was able to resolve it by setting the sanitize option for marked to false. Here's some code:
App.Markdown = React.createClass({
propTypes: {
content: React.PropTypes.string
},
shouldComponentUpdate() {
return true;
},
renderHTML() {
let content = this.props.content;
return {
__html: marked.parse(content, {
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
})
};
},
render() {
return (
<module className="markdown module">
<markdown className="render markdown"
dangerouslySetInnerHTML={this.renderHTML()}></markdown>
</module>
);
}
});
You'd probably want to move the options into a prop for the component so they can be more easily toggled.