Hello, I’m attempting to build the markdown previewer and having some issues getting the markdown rendering correctly in the preview window. At first, before researching and learning about using dangerouslySetInnerHTML
, all input in the editor would render the literal html tags like this:
Here is the code from my Preview component in React:
let marked = require("marked");
class Preview extends Component {
render() {
return (
<div>
<div
id="preview"
value={this.props.value}
//dangerouslySetInnerHTML={{ __html: marked(this.props.value) }}
>
{marked(this.props.value)}
</div>
<div />
</div>
);
}
}
export default Preview;
After doing some research, I figured all I need to do is properly set the html using dangerouslySetInnerHTML
class Preview extends Component {
render() {
return (
<div>
<div
id="preview"
value={this.props.value}
dangerouslySetInnerHTML={{ __html: marked(this.props.value) }}
></div>
<div />
</div>
);
}
}
But I’m left with this as the result:
Here is a link to the project on GitHub: GitHub - artbaker82/markdown-previewer
I’ve been troubleshooting this for hours now and I have yet to come up with a solution. What is going on here?