16

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?

3
  • So if you know of a method, why not try it? Don't forget to link to the jQuery library. It's a very easy and common mistake for people to attempt to use jQuery and forget to include the library. Commented Aug 6, 2015 at 8:33
  • I've alredy tried it, but somehow it's not working. I guess It's because of my bad syntax. Commented Aug 6, 2015 at 8:34
  • It would be a good idea for you to display your attempts. Some people will use your attempt to debug, correct it and explain why it wouldn't work for you. Commented Aug 6, 2015 at 8:36

1 Answer 1

29

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.