Build a Markdown Previewer Marked JS failing test case

Need help to pass marked.js test case

4. When I enter GitHub flavored markdown into the #editor element, the text is rendered as HTML in the #preview element as I type (Hint: You don't need to parse Markdown yourself - you can import the Marked library for this:

Code block where I’m using marked to markdown input text.

createMarkup() {
    return {
      __html: marked(this.props.text, {sanitize: true})

My codepen project link :

Although I’m using marked.js and everything is working as expected (fine) but with this failing test case, I’m not able to figure out where I’m doing wrong. I seek valuable guidance.

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0.

Link to the challenge:

1 Like

This is the key phrase, “…the text is rendered as HTML in the #preview element…” It isn’t very specific, but what it means that it is rendered directly in the #preview element. But you have it in a span that’s a child of that element. This is further confirmed by the rest of the error message, “the text is rendered as HTML in the #preview element as I type#preview’s only children should be those rendered by marked.js …”

So, there should be nothing inside that element, except what marked is going to provide it. See if you can solve it with that information.


That solved the problem. Thanks Sir

Same problem here, but I’m rendering directly into an element. No idea what’s going on here. It took maybe 10 minutes to write, but I’ve spent close to 20 hours trying to figure out how to pass test #4. Either it is a faulty test and needs to be rewritten or FCC is not including all requirements of the test.

class Previewer extends React.Component {
  constructor(props) {
    this.state = {
      defaultContent: `# H1

## H2

[Link Text](#)



const abba = (a) => {
return b + a;

You want a list?
1. Here's a list.
+ A list item.
2. Here's another.
+ another list item
+ and another

> Block Quotes!
> block quotes, man

**Bold Text**

![React Logo](
      content: null
    this.handleChange = content => {
      this.setState({ content });
  render() {
      breaks: true
    const renderer = new marked.Renderer(); = (href, title, text) => {
      return `<a target="_blank" href="${href}">${text}</a>`;
    return (
      <div id="App">
          placeHolder={this.state.content || this.state.defaultContent}
          onChange={e => this.handleChange(}
          {this.state.content || this.state.defaultContent}
            __html: marked(this.state.content || this.state.defaultContent, {
              sanitize: false
ReactDOM.render(<Previewer />, document.getElementById("root"));