Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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'>
</div>


              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Russo+One");

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#container {
  padding: 20px;  
}

textarea {
  width: 99%;
  min-height: 200px;
  margin-bottom: -5px;
  resize: vertical;
  outline: none;
  padding-left: 5px;
  padding-top: 5px;
  font-size: 12px;
}

#preview {
  padding: 10px;
  border-color: silver;
  border-style: solid;
  border-width: 0.1px;
}

#preview blockquote {
  border-left: 3px solid #224B4B;
  color: #224B4B;
  padding-left: 5px;
  margin-left: 25px;
}

#preview code {
  background: white;
  padding: 1px 4px 2px 4px;
  font-size: 12px;
  font-weight: bold;
}

#preview pre {
  background: white;
  padding: 5px 0 5px 5px;
}
#preview h1 {
  border-bottom: 2px solid #224B4B;
}
#preview h2 {
  border-bottom: 1px solid #224B4B;
}
#preview table {
  border-collapse: collapse;
}
#preview td,
#preview th {
  border: 2px solid #224B4B;
  padding-left: 5px;
  padding-right: 5px;
}


h2.component {
  background: linear-gradient(transparent 80%, #FAE438 80%);
}
              
            
!

JS

              
                class PreviewArea extends React.Component {
  constructor(props) {
    super(props)
  }
   
  // propsはrenderの引数では渡されないので、クラスのインスタンス変数的にthisを使ってアクセス
  render() {
    const convertedText = marked(this.props.input, 
                                  { breaks: true })
    // ReactのdangerouslySetInnerHTMLを利用
    // Ref. https://ja.reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
    return (
      <div id="previewWrapper">
        <h2 class='component'>Preview Markdown</h2>
        <div id='preview' dangerouslySetInnerHTML={{
        __html: convertedText
      }}>
        </div>
      </div>
    )
  }
}


class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = { input: placeholder }
    this.handleChange = this.handleChange.bind(this)
  }

   // 入力フィールドのイベントは引数として渡される
   // この値をsetStateに利用する
   handleChange(event) {
     this.setState({
       input: event.target.value
     })
   }

  render() {
    return(
      <div id='container'>
        <h2 class='component'>Input Markdown Text</h2>
        <textarea id='editor' onChange={ this.handleChange }>
          {this.state.input}
        </textarea>
        <PreviewArea input={ this.state.input } />
      </div>
    )
  } 
}

const placeholder = 
`# Welcome to my React Markdown Previewer!

## This is a sub-heading...
### And here's some other cool stuff:
  
Heres some code, \`<div></div>\`, between 2 backticks.

\`\`\`
// this is multi-line code:

function anotherExample(firstLine, lastLine) {
  if (firstLine == '\`\`\`' && lastLine == '\`\`\`') {
    return multiLineCode;
  }
}
\`\`\`
  
You can also make text **bold**... whoa!
Or _italic_.
Or... wait for it... **_both!_**
And feel free to go crazy ~~crossing stuff out~~.

There's also [links](https://www.freecodecamp.com), and
> Block Quotes!

And if you want to get really crazy, even tables:

Wild Header | Crazy Header | Another Header?
------------ | ------------- | ------------- 
Your content can | be here, and it | can be here....
And here. | Okay. | I think we get it.

- And of course there are lists.
  - Some are bulleted.
     - With different indentation levels.
        - That look like this.


1. And there are numbererd lists too.
1. Use just 1s if you want! 
1. But the list goes on...
- Even if you use dashes or asterisks.
* And last but not least, let's not forget embedded images:

![React Logo w/ Text](https://goo.gl/Umyytc)
`

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

Console