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

              
                html, body {
  box-sizing: border-box;
  margin: 0;
  background-color: #f3eacb;
  color: #704214;
}

#root {
  display: flex;
  justify-content: center;
  padding: 3em 0;
}

#content: {
  width: 100%;
}

nav {
  text-align: center;
  padding-bottom: 0.6em;
}

button {
  background-color: #a25f1d;
  color: #f3eacb;
  border: 1px solid #000;
  border-radius: 10px;
  margin: 0 5px;
  padding: 5px
}

#editor {
  display: block;
  resize: vertical;
  margin: 0 auto;
  font-size: 14px;
  width: 500px;
  max-width: 80vw;
  height: 200px;
  background-color: #fffaea;
  color: #56320e;
  border: 1px solid black;
  -webkit-box-shadow: 0px 0px 7px 2px #000000; 
box-shadow: 0px 0px 5px 0.5px #000000;
}

#preview {
  border: 1px solid black;
  background-color: #fffaea;
  box-shadow: 0px 0px 5px 0.5px #000000;
}

#preview img {
  width: 100px;
  height: 100px;
}

#preview, footer {
  margin: 2.5em 1em 0 1em;
  padding: 0 0.5em;
}

footer {
  text-align: center;
}

code, pre {
  background-color: #ffffff;
  font-weight: bold;
}

blockquote {
  border-left: 3px solid #ccc;
  padding-left: 15px;
  font-family: 'Domine', serif;
}

.expand {
  min-width: 90vw;
  min-height: 90vh;
}
              
            
!

JS

              
                // import React, {useState, useEffect} from "https://cdn.skypack.dev/react";

const {useState, useEffect} = React
// import ReactDOM from "https://cdn.skypack.dev/react-dom";
 import {marked} from "https://cdn.skypack.dev/marked"
// import './index.css';
// import App from './App';
// import reportWebVitals from './reportWebVitals';

const defText = `# My Markdown previewer!

## Completely built in React!
For a guide to markdown, just follow [this handy link](https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf)

Inline code is written by wrapping your text in backticks, like so: \`<p>React is pretty good, actually</p>\`

Code blocks are written by wrapping your code in three backticks!

\`\`\`javascript
function consume(food){
    if (food.isEdible)
      return devour;
}
\`\`\`

Lists and blockquotes can be done in markdown as well

* Work
* Study
* Socialize

> __This took way too long to make__
> __But at least I'm done__

Finally, markdown allows images too.
![Github logo](https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Unofficial_JavaScript_logo_2.svg/240px-Unofficial_JavaScript_logo_2.svg.png)`

let renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
    let link = marked.Renderer.prototype.link.apply(this, arguments);
    return link.replace("<a","<a target='_blank'");
};

marked.setOptions({
    renderer: renderer
});

const Container = () => {
  const [text, setText] = useState(defText)
  const [expandEditor, setEditor] = useState(false)
  const [expandPreview, setPreview] = useState(false)
  const [isVisiblePreview, setIsVisiblePreview] = useState(true)
  const [isVisibleEditor, setIsVisibleEditor] = useState(true)

  const changeText = (event) => {
    setText(event.target.value)
  }

  const alterEditor = () => {
    setEditor(true)
    setIsVisiblePreview(false)
  }

  const alterPreview = () => {
    setPreview(true)
    setIsVisibleEditor(false)
  }

  const reset = () => {
    setIsVisibleEditor(true)
    setIsVisiblePreview(true)
    setPreview(false)
    setEditor(false)
  }

  return (<div id="content">
      <Navbar altEdit={alterEditor} 
        altPrev={alterPreview} 
        isVisiblePreview={isVisiblePreview} 
        isVisibleEditor={isVisibleEditor} 
        reset={reset}/>
      <Main changeText={changeText} 
        input={text} 
        isVisiblePreview={isVisiblePreview} 
        isVisibleEditor={isVisibleEditor} 
        expandEditor={expandEditor} 
        expandPreview={expandPreview}/>
        <Footer />
    </div>)
}

const Navbar = (props) => {
  return (props.isVisiblePreview && props.isVisibleEditor) ? (<nav>
        <button onClick={props.altEdit}>Editor</button>
        <button onClick={props.altPrev}>Preview</button>
    </nav>) : (<nav>
        <button onClick={props.reset}>Reset default</button>
    </nav>)
}

const Main = (props) => {
  marked.setOptions({
    breaks: true
  })

  let markedText = {__html: marked(props.input)}
  return (props.isVisiblePreview && props.isVisibleEditor) ?
      (<div>
        <textarea id="editor" value={props.input} onChange={props.changeText} className={props.expandEditor && "expand"}></textarea>
        <div id="preview" className={props.expandPreview && "expand"} dangerouslySetInnerHTML={markedText}></div>
      </div>) : !props.isVisiblePreview ? 
      (<div>
        <textarea id="editor" value={props.input} onChange={props.changeText} className={props.expandEditor && "expand"}></textarea>
      </div>) : 
      (<div>
        <div id="preview" className={props.expandPreview && "expand"} dangerouslySetInnerHTML={markedText}></div>
      </div>)
}

const Footer = (props) => {
  return (<footer>
    <p>Made by <a href="https://codepen.io/Elemeandor" target="_blank">Darnell</a></p>
  </footer>)
}


ReactDOM.render(
  <React.StrictMode>
    <Container />
  </React.StrictMode>,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
// reportWebVitals();
              
            
!
999px

Console