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

              
                body, html, div{
  padding: 0;
  margin: 0;
}

*{
  box-sizing: border-box;
}

.main-container{
  display: grid;
  height: 100vh;
  width: 100%;
  display: grid;
  grid-template-columns: 3fr 4fr;
  grid-template-areas: 'editor preview';
}

#editor, #editor:focus{
  grid-area: editor;
  height: 100%;
  width: 100%;
  padding: 20px;
  background: #002b36;
  border: none;
  font-size: 16px;
  color: #fdf6e3;
  font-family: 'Inconsolata', monospace;
  outline: none;
}

#previewContainer{
  grid-area: preview;
  font-family: 'Open Sans', sans-serif;
  padding: 40px;
  overflow-y: scroll;
}

#preview img{
  width: 100px;
  margin: 20px;
  vertical-align: middle;
}

 pre, code {
   font-family: 'Inconsolata', monospace;
   background: #272822;
   color: #eee8d5;
   padding: 2px 5px;
   border-radius: 2px;
}

pre{
  padding: 15px;
  border-radius: 5px;
}

blockquote{
  font-size: 14px;
  background: #f7f7f7;
  padding: 5px 10px;
  border-left: 3px solid #121212;
}
              
            
!

JS

              
                // Using Redux for a project as simple as this is overkill, but is done nonetheless for the sake of practice

// Declartions
const {useState} = React;
const {createStore} = Redux;
const {Provider, connect} = ReactRedux;

const INPUT = 'INPUT';

// Redux
const inputAction = (value) => ({
  type: INPUT,
  payload: value
});


const initialDoc = `# React-Redux Markdown Previewer!

## Redux was Overkill
### But I used it anyways

Interestingly the HTML only has **one element**, \`<div id="root"></div>\`

\`\`\`
// but the javascript is filled with many functions like this:

const mapStateToProps = state => ({
  textareaInput: state.textareaInput
});
\`\`\`

I like to listen to Eminem when I code sometimes
> You gotta find that inner strength to pull that shit out of you, and get that motivation to not give up and not be a quitter!

[Google can be quite helpful!](https://www.google.com)

Technologies used
- React
- Redux
  - React-Redux
-SCSS


![redux](https://cdn.worldvectorlogo.com/logos/redux.svg)
![react](https://miro.medium.com/max/500/1*cPh7ujRIfcHAy4kW2ADGOw.png)
![sass](https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Sass_Logo_Color.svg/1200px-Sass_Logo_Color.svg.png)
`;


const initState = {
  textareaInput: initialDoc
}

const inputReducer = (state=initState, action) => {
  switch(action.type){
    case INPUT:
      return {
        textareaInput: action.payload
      };
    default:
      return state;
  }
}

// Editor Component
const Editor = (props) => {
  
  textareaChanged = (e) => {
    props.setInput(e.target.value);
  }
  
  return(
    <div className="editor-container">
      <textarea id="editor" name="textarea" value={props.textareaInput} onChange={textareaChanged} />
    </div>
  )
}

// Preview Component
const Preview = (props) => {
  markdown = marked(props.textareaInput);
  return(
    <div id="previewContainer">
      <div id="preview" dangerouslySetInnerHTML={{__html: markdown}}></div>
    </div>
  )
}

const mapStateToProps = state => ({
  textareaInput: state.textareaInput
});

const mapDispatchToProps = dispatch => ({
  setInput: val => {
    dispatch(inputAction(val))
  }
});

const ConnectedEditor = connect(mapStateToProps, mapDispatchToProps)(Editor);
const ConnectedPreview = connect(mapStateToProps, mapDispatchToProps)(Preview);

// Main Render
const store = createStore(inputReducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());

const App = () => {
  return (
    <Provider store={store}>
      <div className="main-container">
        <ConnectedEditor/>
        <ConnectedPreview/>
      </div>
    </Provider>
  )
}
ReactDOM.render(<App/>, document.getElementById('root'));
              
            
!
999px

Console