Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id='app' class='container-fluid'> </div>
<script src='https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js'></script>
              
            
!

CSS

              
                body {
  background-color: #3D9970;
}

#preview {
  background-color: white;
  min-height: 600px;
}

img {
  max-width: 100%;
}

#editor {
  min-height: 600px;
}


              
            
!

JS

              
                class App extends React.Component {
  state = {
    text: placeholder,
  }
  
  //when something changes in input box, text value is being updated here
  handleChange = (e) => {
    this.setState({
      text: e.target.value
    })
  }
  
  render() {
    const { text } = this.state;
    
   //we used marked.parse function to parse the text entered on the left side and interpret it correctly 
    const markdown = marked.parse(this.state.text);
   
    
    return (
   <div>   
     <h2 className='text-center mt-4'>Convert Your Markdown</h2>
      <div className='row'>
        
        
        <div className='col-6'>
          <h6 className='text-center'>Enter markdown here: </h6>       
          
          <textarea className='form-control' id="editor" value={text} onChange={this.handleChange} />
        </div>  
        
        <div className='col-6'>
          <h6 className='text-center'>See the result:</h6>
          
          <div className='preview rounded' dangerouslySetInnerHTML = {{__html: markdown}} id="preview"/>
         </div>  
        
        
      </div>  
  </div>    
    )
    
  }
} 
//markdown test text, intial text in left box that is interpreted by soft on right side.
const placeholder = `# Markdown Previewer

[![Markdown Previewer](https://raw.githubusercontent.com/amr-adel/fcc-markdown-previewer/master/public/demo.jpg "Markdown Previewer")](https://amr-adel.github.io/fcc-markdown-previewer/)

## FreeCodeCamp | Front End Libraries Projects

A *FreeCodeCamp* challenge on using front end libraries to build a markdown previewer with the below user stories to be fulfilled:

> **Required**
> 1. I can see a \`textarea\` element with a corresponding \`id="editor"\`.
> 2.  I can see an element with a corresponding \`id="preview"\`.
> 3. When I enter text into the \`#editor\` element, the \`#preview\` element is updated as I type to display the content of the textarea.
> 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: https://cdnjs.com/libraries/marked).
> 5. When my markdown previewer first loads, the default text in the \`#editor\` field should contain valid markdown that represents at least one of each of the following elements: a header (H1 size), a sub header (H2 size), a link, inline code, a code block, a list item, a blockquote, an image, and bolded text.
> 6. When my markdown previewer first loads, the default markdown in the \`#editor\` field should be rendered as HTML in the \`#preview\` element.

> **Optional Bonus**
> 1. When I click a link rendered by my markdown previewer, the link is opened up in a new tab (HINT: read the Marked.js docs for this one!).
> 2. When I click a link rendered by my markdown previewer, the link is opened up in a new tab (HINT: read the Marked.js docs for this one!).

---

\`\`\`                      
   <p>Hello world! This is HTML CODE BLOCK.</p>          
\`\`\`

---

#### More about the challenge [Build a Markdown Previewer](https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-markdown-previewer).
#### See it in action [HERE](https://amr-adel.github.io/fcc-markdown-previewer/).`;

ReactDOM.render(<App />, document.getElementById('app'));
              
            
!
999px

Console