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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

<div id="app"></div>
              
            
!

CSS

              
                
$windowShadow: 1px 5px 10px 2px #000000;
$windowBorder: 1px solid #000;
$windowBackgroundColor: #c0c0c0;
$windowContentPadding: 5px;
$mainPageBackgroundColor: #d2b48c;
$toolbarColor: #008080;
$windowContainerMarginBottom: 20px !important;

%windowMainContent {
  width: 100%;
  height:100%;
  border: $windowBorder;
  background-color: $windowBackgroundColor;
  padding: $windowContentPadding;
  box-shadow: $windowShadow;
}


html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

.container-fluid {
  /*background-color:#000;*/
  /*
  padding:0;
  margin:0;*/
}

body {
  background-color: $mainPageBackgroundColor;
  padding:0;
  margin:0;
}

.fa-arrows-alt, .fa-compress {
  position: absolute;
  right: 5px;
  top: 5px;
}

.fa-arrows-alt:hover, .fa-compress:hover { color:#c0c0c0; }

.windowLabel {
  color: black;
  font-weight: bold;
}

#editorContainer {
  max-width: 700px;
  min-height: 300px;
  padding:0;
  /*margin-bottom: 20px !important;*/
  margin: auto;
  /*background: #000;*/
  
  margin-bottom: $windowContainerMarginBottom;
}

#editorContentContainer {
  height: 90%;
}

#editor {
  @extend %windowMainContent;
}

#previewContainer {
  max-width: 1000px;
  height: 100%;
  padding:0;
  /*margin-top: 20px;*/
  margin-bottom: $windowContainerMarginBottom;
  /*background: #000;*/
}

#previewContentContainer {
  height:95%;
}

#preview {
  @extend %windowMainContent;
}

.toolbar {
  background-color: $toolbarColor;
  border: $windowBorder;
  width: 100%;
  height: 30px;
  box-shadow: $windowShadow;
  z-index: 100;
}

.maximized {
  max-width: 100% !important;
  width:98vw !important;
  height: 100vh;
  padding:0;
  margin: 0 auto 0 auto !important;
  
  /*
  position: absolute; 
  top: 0;
  left: 0;
 */
  
}

.hide {
  display: none;
}


/********** MARKDOWN PREVIEWER ************/

table, th, td {
  border: 1px solid black;
  padding: 2px;
}

pre {
  
  background-color: #fff;
  padding:5px;
}

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

blockquote {
  border-left: 3px solid #008080;
  color: #000;
  padding-left: 5px;
  margin-left: 25px;
}
  
              
            
!

JS

              
                const projectName = 'markdown-previewer';

// ALLOWS LINE BREAKS WITH RETURN BUTTON
marked.setOptions({
breaks: true
});

//console.log(marked);

// INSERTS target="_blank" INTO HREF TAGS (required for codepen links)
const renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
return `<a target="_blank" href="${href}">${text}` + '</a>';
};

class App extends React.Component {
    
    constructor(props) {

        super(props);

        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. And last but not least, let's not forget embedded images:

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

        this.state = {'markdown': placeholder, 'editorMaximized': false, 'previewerMaximized': false};
        
        this.handleChange = this.handleChange.bind(this);
        this.handleEditorMaximize = this.handleEditorMaximize.bind(this);
        this.handlePreviewMaximize = this.handlePreviewMaximize.bind(this);
    }
    
    handleChange(event) {
        //console.log(event.target.value);
        this.setState({'markdown' : event.target.value});
    }
    
    handleEditorMaximize(event) {
        this.setState({editorMaximized: !this.state.editorMaximized});
        //console.log(event);
    }

    handlePreviewMaximize(event) {
        this.setState({previewerMaximized: !this.state.previewerMaximized});
    }
    
    render() {
        
        let editorClasses = {container: '', maximizeIcon: 'fa fa-arrows-alt'};
        let previewerClasses = {container: '', maximizeIcon: 'fa fa-arrows-alt'};
        
        if (this.state.editorMaximized) {

            editorClasses['container'] = 'maximized';
            editorClasses['maximizeIcon'] = 'fa fa-compress';
            
            previewerClasses['container'] = 'hide';
        }
        else if (this.state.previewerMaximized) {
            
            editorClasses['container'] = 'hide';

            previewerClasses['container'] = 'maximized';
            previewerClasses['maximizeIcon'] = ' fa fa-compress';
        }
        
        return (
            
            <div className="container-fluid mx-auto mt-2" >
                <div className="row">
                    <div className="col">
                        <Editor classes={editorClasses} markdown={this.state.markdown} handleMaximize={this.handleEditorMaximize} handleChange={this.handleChange} />
                    </div>
                </div>
                <div className="row">
                    <div className="col">
                        <Previewer classes={previewerClasses} markdown={this.state.markdown} handleMaximize={this.handlePreviewMaximize} />
                    </div>
                </div>
            </div>

        );
    }
};

const Editor = (props) => {

    const editorContainer = props.classes['container'];
    const icon = props.classes['maximizeIcon'];
    
    // I think this is safe?
    window.scrollTo(0, 0);
        
    return (
        <div id="editorContainer" className={`row mx-auto  ${editorContainer}`}>
            <div  className="col">
                <div className="row">
                    <div className="col">
                        <div id="" className="col  text-center mx-auto toolbar">
                            <span className="windowLabel">Editor</span><i className={`${icon}`} title='' onClick={props.handleMaximize} />
                        </div>
                    </div>
                </div>
                <div  id="editorContentContainer" className="row">
                    <div className="col">
                        <textarea id="editor" type="text" onChange={props.handleChange} value={props.markdown}></textarea>
                    </div>
                </div>
            </div>
        </div>
    );

};

const Previewer = (props) => {

    const previewContainer = props.classes['container'];
    const icon = props.classes['maximizeIcon'];
        
    // I think this is safe?
    window.scrollTo(0, 0);
    
    return (
        <div id="previewContainer" className={`row mx-auto ${previewContainer}`}>
            <div className="col">
                <div className="row">
                    <div className="col">
                        <div id="" className="col  text-center mx-auto toolbar">
                            <span className="windowLabel">Previewer</span><i className={`${icon}`} title='' onClick={props.handleMaximize} />
                        </div>
                    </div>
                </div>
                <div  id="previewContentContainer" className="row">
                    <div className="col">
                        <div id="preview" className="mx-auto" 
                                dangerouslySetInnerHTML={{__html: marked(props.markdown, { renderer: renderer })}} />
                    </div>
                </div>
            </div>
        </div>
    );

};

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

              
            
!
999px

Console