You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/tutorial.md
+9-11Lines changed: 9 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -212,7 +212,7 @@ Note that we have passed some data from the parent `CommentList` component to th
212
212
213
213
Markdown is a simple way to format your text inline. For example, surrounding text with asterisks will make it emphasized.
214
214
215
-
First, add the third-party **Showdown** library to your application. This is a JavaScript library which takes Markdown text and converts it to raw HTML. This requires a script tag in your head (which we have already included in the React playground):
215
+
First, add the third-party library **marked** to your application. This is a JavaScript library which takes Markdown text and converts it to raw HTML. This requires a script tag in your head (which we have already included in the React playground):
216
216
217
217
```html{7}
218
218
<!-- index.html -->
@@ -221,41 +221,39 @@ First, add the third-party **Showdown** library to your application. This is a J
All we're doing here is calling the Showdown library. We need to convert `this.props.children` from React's wrapped text to a raw string that Showdown will understand so we explicitly call `toString()`.
246
+
All we're doing here is calling the marked library. We need to convert `this.props.children` from React's wrapped text to a raw string that marked will understand so we explicitly call `toString()`.
248
247
249
248
But there's a problem! Our rendered comments look like this in the browser: "`<p>`This is `<em>`another`</em>` comment`</p>`". We want those tags to actually render as HTML.
250
249
251
250
That's React protecting you from an XSS attack. There's a way to get around it but the framework warns you not to use it:
252
251
253
-
```javascript{5,11}
252
+
```javascript{4,10}
254
253
// tutorial7.js
255
-
var converter = new Showdown.converter();
256
254
var Comment = React.createClass({
257
255
render: function() {
258
-
var rawMarkup = converter.makeHtml(this.props.children.toString());
256
+
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
259
257
return (
260
258
<div className="comment">
261
259
<h2 className="commentAuthor">
@@ -268,9 +266,9 @@ var Comment = React.createClass({
268
266
});
269
267
```
270
268
271
-
This is a special API that intentionally makes it difficult to insert raw HTML, but for Showdown we'll take advantage of this backdoor.
269
+
This is a special API that intentionally makes it difficult to insert raw HTML, but for marked we'll take advantage of this backdoor.
272
270
273
-
**Remember:** by using this feature you're relying on Showdown to be secure.
271
+
**Remember:** by using this feature you're relying on marked to be secure. In this case, we pass `sanitize: true` which tells marked to escape any HTML markup in the source instead of passing it through unchanged.
0 commit comments