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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                #markDownPreview
              
            
!

CSS

              
                body{
 background-image: url("https://www.desktopbackground.org/t/2012/07/18/422827_ugly-wallpapers-wallpapers-cave_3648x2736_h.jpg");
}

#preview,
.title {
  display: inline-block;
}


.editorWrap {
  width: 799px;
  margin: 8px auto;
  textarea {
    width: 99%;
    min-height: 300px;
    margin-bottom: -5px;
    resize: vertical;
    outline: none;
    padding-left: 5px;
    padding-top: 5px;
    font-size: 12px;
  }
}

.spaceBetweenEditorAndPreviewer {
  width: 10px;
  height:20px;
  text-align: center;
  font-size: 10px;
  margin: auto;
}

.previewWrap {
  background: gray;
  width: 800px;
  margin: 20px auto;
  padding-right: 27px;
  #preview {
    margin-left: 5px;
    margin-top: -10px;
    width: 97%;
  }
}

#preview {
  blockquote {
    border-left: 300px solid;
    color: blue;
    padding-left: 15px;
    margin-left: 10px;
  }

  code {
    background: white;
    padding: 1px;
    font-size: 15px;
    font-weight: bold ;
  }

  pre {
    background: white;
    padding: 30px;
  }
}
              
            
!

JS

              
                marked.setOptions({
  breaks: true,
});

//https://github.com/markedjs/marked/issues/655
//https://marked.js.org/#/USING_PRO.md#renderer
const thisRenderer = new marked.Renderer();
thisRenderer.link = function (href, title, text) {
  return `<a target="_blank" href="${href}">${text}` + '</a>';
}

class MarkDownPreview extends React.Component{
  constructor(props) {
    super(props);
    this.state =  {
      textToMark: startingText,
    }
    this.handleChange = this.handleChange.bind(this);
  }
  handleChange(textInEditor) {
    this.setState({
      textToMark: textInEditor.target.value
    });
  }

 render() {
    return (
      <div>
        <div className="editorWrap">
          <Editor textToMark={this.state.textToMark} 
            onChange={this.handleChange} />
        </div>
        <div className="spaceBetweenEditorAndPreviewer">
        </div>
        <div className="previewWrap">
          <Preview  textToMark={this.state.textToMark}/>
        </div>
      </div>
    )
  }
};

const Editor = (props) => {
  return (
    <textarea id="editor"
      value={props.textToMark}
      onChange={props.onChange}
      type="text"/>
    )
}

//https://reactjs.org/docs/dom-elements.html
const Preview = (props) => {
  return (
      <div id='preview' dangerouslySetInnerHTML={{__html: marked(props.textToMark, { renderer: thisRenderer })}} />
    )
}

const startingText = 
`# One hashtag / pound sign leads to text in H1.

## Two hashtags lead to text in H2.
### Three hashtags leads to text in H3.
###### This is H6 text.
  
Three backticks lead to a code window.
\`\`\`
// Here is a code block:

function incrementByOne(numberToIncrease) {
    return numberToIncrease + 1;
}
\`\`\`
Three more backticks end the code window.

Two astericks start and stop **bold text**.
Underscores start and stop _italic text_.

\`[Something](www.aWebPage.com) is the same as <a src="www.aWebPage.com">Something</a>  \`

[A link to Google](http://www.google.com)

> Block Quotes are started with a \>.

1. Listed items start with a 1. 
1. I stripped out what I could and still have a passing result.
1. I think this is sufficient.

Here is an embedded image
![Google Image](https://www.blog.google/static/blogv2/images/google-200x200.7714256da16f.png)
`

ReactDOM.render(<MarkDownPreview />, document.getElementById('markDownPreview'));


              
            
!
999px

Console