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="root"></div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Medula+One|Open+Sans');
$bg : #503228;
$text : white;
$text-viewer : black;
$bg-nav: #494949;

* {
  box-sizing: border-box;
}
html, body {
  height: 100%;
  width: 100%;
  font-size:16px;
}
body{
  margin: 0;
  padding: 0;
  background: url(http://res.cloudinary.com/deyh3ywme/image/upload/v1504001961/markdown-bg_e62gma.jpg) no-repeat center center fixed;
  background-size: cover;
  background-color: $bg;
  color: $text;
  font-family: 'Open Sans', sans-serif;
}
.display-list{
ul{
  list-style-type: none;
}
li{
  display:inline;
}
}
button{
 -webkit-appearance: none; //remote safari defaults
  border-radius: 0;
  border-style: none;
  font-family: 'Open Sans', sans-serif;
  cursor: pointer;
}
.btn-select-display{
  border: 1px solid #DEA438;
  background-color: $bg;
  color: #bfbfbf;
  padding: 2px;
}
.btn-clear{
  border: 1px solid #494949;
  border-radius: 2px;
  background: url('http://res.cloudinary.com/deyh3ywme/image/upload/v1505938240/close-icon_qxtkry.png') center no-repeat;
  background-color: rgba(0, 0, 0, 0.1);
  height: 24px;
  width: 24px;
}
.btn-example{
  border: none;
  border-radius: 2px;
  background: url('http://res.cloudinary.com/deyh3ywme/image/upload/v1505938240/MD-icon_hwauv2.png') center no-repeat;
  height: 24px;
  width: 24px;
}
.container{
  height: 100vh;
  display: flex;
  flex-flow: column nowrap;
}
header {
  padding: 0;
  flex: 0.1 1 auto;
  background-color: $bg-nav;
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-around;
  align-items: center;
  min-height: 60px;
  h1{
    font-size: 2.5em;
    padding: 0;
    margin: 0;
    font-family: 'Medula One', cursive;
    font-weight: normal;
  }
}
article {
 flex: 2 1 auto;
 display: flex;
 flex-flow: row nowrap;
 }
section{
  flex: 1 1 50%;
  max-width:50%;
  background-color: #C64212;
  border: 2px solid #DEA438;
  border-radius: 5px;
  padding: 1em;
  display: flex;
  flex-flow: column nowrap;
}
.display-none{
    display:none;
  }
%inner-flex{
  flex: 1 1 100%; //the use of 100% flex basis gives the child elements a height to work with, solves my mobile safari problem!
  display: flex;
  flex-flow: column nowrap;
}
.markdown-output {
  @extend %inner-flex;
  .header{
    flex: 0.1 1 auto;
    max-height: 30px;
    font-size: 1em;
    margin: 0;
    padding: 0 0 1em 0;
    text-align: center;
  }
}
.output-text {
    flex: 2 1 auto;
    background-color: white;
    padding: 0 7px;
    border-radius: 5px;
    color: $text-viewer;
    overflow: auto;
}
.markdown-form{
  color: $text-viewer;
   @extend %inner-flex;
  label{
    font-size: 1em;
    color: $text;
  }
  textarea[type='text']{
    flex: 2 1 auto;
    font-family: 'Open Sans', sans-serif;
    padding: 20px 7px 0 7px;
    border: none;
    border-radius: 5px;
    resize: none;
    overflow: auto;
  }
}
.markdown-header{
  flex: 0.1 1 auto;
  display: flex;
  justify-content: space-between;
  max-height: 30px;
 }
footer{
  flex: 0.1 1 auto;
  align-self: center;
  a{
    color: #C64212;
    text-decoration: none;
    img {
    margin: 0 0.5em;
    width: 1.5em;
    height: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s, visibility 0.4s;
  }
    &:hover >img{
      color: #DEA438;
      visibility: visible;
      opacity: 1;
  }
  }
}

/* mobile first, so this is for larger screens and also for landscape views */
@media only screen and (min-width: 700px)  {
  section {
      min-width: 40%;
    margin: 5%;
  }
}


              
            
!

JS

              
                let exampleText = 'Heading\n=======\n\nSub-heading\n-----------\n \n### Another deeper heading\n \nParagraphs are separated\nby a blank line.\n\nLeave 2 spaces at the end of a line to do a  \nline break\n\nText attributes *italic*, **bold**, \n`monospace`, ~~strikethrough~~ .\n\nShopping list:\n\n  * apples\n  * oranges\n  * pears\n\nNumbered list:\n\n  1. apples\n  2. oranges\n  3. pears\n\nThe rain---not the reign---in\nSpain.\n\n *[Herman Fassett](https://freecodecamp.com/hermanfassett)*';


function SelectDisplayType(props){
  const displays= ["Markdown", "Browser", "Dual View"];
  const activeBtnStyle = {
    backgroundColor: "#C64212",
    color: "#ffffff"
  }
  return (
    <ul className="display-list">
      {displays.map((display) =>{
        return(
          <li
            key={display}>
            <button className="btn-select-display"
              style={display === props.selectedDisplay ? activeBtnStyle : null}
              onClick={props.updateDisplay.bind(null,display)}
              >{display}</button>
          </li>)
      })}
    </ul>
  )
}
class App extends React.Component{
  constructor(props){
  super(props);
  this.state = {
    selectedDisplay: "Dual View"
  }
  this.updateDisplay = this.updateDisplay.bind(this);
  }
  updateDisplay(display) {
    this.setState( () => {
      return {
        selectedDisplay: display
      }
    });
  }
  render(){
    return(
      <div className="container">
        <Header
          selectedDisplay={this.state.selectedDisplay}
          updateDisplay={this.updateDisplay}
        />
        <FilteredView
          selectedDisplay={this.state.selectedDisplay}
        />
        <Footer />
      </div>
    )
  }
}
function Header(props){
  return(
    <header>
     <h1>Markdown Viewer</h1>
       <SelectDisplayType
         selectedDisplay={props.selectedDisplay}
         updateDisplay={props.updateDisplay}
       />
     </header>
  )
}
function Footer(){
  return(
    <footer>Brought to you by
      <a
        href="http://olivercule.com"
        target="_blank"
        > Oliver Cule<img
          src="http://res.cloudinary.com/deyh3ywme/image/upload/v1505078888/oc-final_yerb3t.png"/>
        </a>
      </footer>
  )
}
class FilteredView extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      markdownText: ''
    };
    this.handleChange = this.handleChange.bind(this);
    this.buttonClickClear = this.buttonClickClear.bind(this);
    this.buttonClickExample =   this.buttonClickExample.bind(this);
  }
  handleChange(event) {
    this.setState({markdownText: event.target.value})
  }
  buttonClickClear(event){
    event.preventDefault();
    this.setState({markdownText: ""})
  }
  buttonClickExample(event) {
    event.preventDefault();
    this.setState({markdownText: exampleText})
  }
render(){
  return(
    <article>
    {this.props.selectedDisplay === "Browser" || <MarkDownInputForm
      buttonClickExample={this.buttonClickExample}
      buttonClickClear={this.buttonClickClear}
      selectedDisplay={this.props.selectedDisplay}
      markdownText={this.state.markdownText}
      onChange={this.handleChange}/>}
    {this.props.selectedDisplay === "Markdown"  || <BrowserViewer
      selectedDisplay={this.props.selectedDisplay}
      textarea={this.state.markdownText}/>}
  </article>
  )
}
}
function Clear(props) {
  return (
    <button
     style= {!props.markdownText ? {visibility: "hidden"} : null}
     className="btn-clear"
     onClick={props.buttonClickClear.bind(this)}
      ></button>
  )
}
function Example(props){
  return(
    <button
      className="btn-example"
      onClick={props.buttonClickExample.bind(this)}></button>)
}
class MarkDownInputForm extends React.Component {
  render(){
    return (
      <section style={this.props.selectedDisplay === "Markdown" ? {maxWidth: "100%" , flex: "1 1 100%"} : null}>
        <form className="markdown-form">
          <div className="markdown-header">
          <Example buttonClickExample={this.props.buttonClickExample}/>
          <label htmlFor='markdown-text'>Markdown</label>
          <Clear markdownText={this.props.markdownText}
                 buttonClickClear={this.props.buttonClickClear}/>
          </div>
          <textarea
            id='markdown-text'
            value={this.props.markdownText}
            onChange={this.props.onChange}
            placeholder="Enter your Markdown here:"
            type="text">
            
            </textarea>
        </form>
      </section>
     )
  };
}

class BrowserViewer extends React.Component {
  createMarkup(value) {
  let markUp = marked(value, {sanitize: true});
  return {__html: markUp};
}
  render(){
    return(
      <section style={this.props.selectedDisplay === "Browser" ? {maxWidth: "100%", flex: "1 1 100%"} : null}>
        <div className="markdown-output">
          <div className="header">Browser view</div>
          <div className="output-text" dangerouslySetInnerHTML={this.createMarkup(this.props.textarea)}>
        </div>
        </div>
      </section>
    );
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

              
            
!
999px

Console