Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  162] [ 2]  / answers: 1 / hits: 31390  / 9 Years ago, thu, august 6, 2015, 12:00:00

This is how the render code looks now (And I know it's unsafe to do so):



render: function() {
return (
<div className=container-fluid pages_container>
<p dangerouslySetInnerHTML={{__html: this.state.page.body}} />
</div>
);
}


The question is how can I render it safely?


More From » jquery

 Answers
15

Reference https://facebook.github.io/react/docs/dom-elements.html#dangerouslysetinnerhtml



<script src=https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js></script>

render: function() {
return (
<div className=container-fluid pages_container>
<p dangerouslySetInnerHTML={{__html: marked(this.state.page.body, {sanitize: true})}} />
</div>
);
}


jsFiddle


[#65521] Tuesday, August 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dorab

Total Points: 22
Total Questions: 106
Total Answers: 99

Location: El Salvador
Member since Fri, May 8, 2020
4 Years ago
dorab questions
Tue, Nov 2, 21, 00:00, 3 Years ago
Wed, Sep 8, 21, 00:00, 3 Years ago
Sun, Jun 13, 21, 00:00, 3 Years ago
Thu, Mar 4, 21, 00:00, 3 Years ago
;