File tree 2 files changed +10
-5
lines changed 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ var MarkdownEditor = React.createClass({
6
6
handleChange: function() {
7
7
this.setState({value: React.findDOMNode(this.refs.textarea).value});
8
8
},
9
+ rawMarkup: function() {
10
+ return { __html: marked(this.state.value, {sanitize: true}) };
11
+ },
9
12
render: function() {
10
13
return (
11
14
<div className="MarkdownEditor">
@@ -17,9 +20,7 @@ var MarkdownEditor = React.createClass({
17
20
<h3>Output</h3>
18
21
<div
19
22
className="content"
20
- dangerouslySetInnerHTML={{
21
- __html: marked(this.state.value, {sanitize: true})
22
- }}
23
+ dangerouslySetInnerHTML={this.rawMarkup()}
23
24
/>
24
25
</div>
25
26
);
Original file line number Diff line number Diff line change @@ -257,14 +257,18 @@ That's React protecting you from an [XSS attack](https://en.wikipedia.org/wiki/C
257
257
``` javascript{4,10}
258
258
// tutorial7.js
259
259
var Comment = React.createClass({
260
- render : function() {
260
+ rawMarkup : function() {
261
261
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
262
+ return { __html: rawMarkup };
263
+ },
264
+
265
+ render: function() {
262
266
return (
263
267
<div className="comment">
264
268
<h2 className="commentAuthor">
265
269
{this.props.author}
266
270
</h2>
267
- <span dangerouslySetInnerHTML={{"{{"}}__html: rawMarkup} } />
271
+ <span dangerouslySetInnerHTML={this. rawMarkup() } />
268
272
</div>
269
273
);
270
274
}
You can’t perform that action at this time.
0 commit comments