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

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>

<!-- 

Hello Camper!

For now, the test suite only works in Chrome! Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

-->
<html>
  <title>Free Code Camp Markdown Challenge - Mariano Hernandez</title>
  <body>
     <div id='App' style="height: 100%">
    </div>
  </body>
</html>
              
            
!

CSS

              
                body,
html {
  height: 100%;
  margin: 0px;
  font-family: "Raleway", sans-serif;
}

@mixin height-calc($percentage, $value) {
  height: -moz-calc(#{$percentage} - #{$value});
  /* WebKit */
  height: -webkit-calc(#{$percentage} - #{$value});
  /* Opera */
  height: -o-calc(#{$percentage} - #{$value});
  /* Standard */
  height: calc(#{$percentage} - #{$value});
}

$lavender: #cfafff;
$yellow: #f4f1af;
$babyblue: #aadff6;
$darkerBlue: #2c7ce8;
$green: #d6f3a1;

.outerDiv {
  height: 100%;
  width: 100%;
  background: $babyblue;
}

.innerDiv {
  background: white;

  min-width: 400px;
  max-width: 600px;
}
.window {
  height: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
}
.windowHide {
  display: none;
}
.windowFrame {
  display: flex;
  flex-direction: column;
  flex-wrap: no-wrap;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.windowHeader {
  width: 100%;
  border: 1px solid grey;
  border-radius: 3px 3px 0px 0px;
  display: block;
  background-color: $darkerBlue;
}
.leftWindowHeader {
  width: 30%;
  text-align: left;
  font-weight: bold;
  display: inline-block;
  padding-left: 5px;
}
.rightWindowHeader {
  width: 70%;
  text-align: right;

  display: inline-block;
  padding-right: 5px;
}
.windowDisplay {
  border-left: 1px solid grey;
  border-right: 1px solid grey;
  border-bottom: 1px solid grey;
  width: 100%;
  height: 100%;
  padding-left: 5px;
}

#editor {
  resize: none;
  height: 100%;
}

#preview {
  overflow-y: scroll;
}

              
            
!

JS

              
                const {render} = ReactDOM
const {Provider, connect} = ReactRedux
const {createStore} = Redux


const MaximizeIcon = () => ( <i className="fas fa-expand"></i> )
const MinimizeIcon = () => (<i className="fas fa-compress"></i>)
marked.setOptions({breaks: true})

const innerText = `# 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)`;



// being setion on redux


const defaultState = {

  windows: {
    fullSize: false,
    editor: {width: 7, fullSize: false, innerText: innerText},
    preview: {width: 5, fullSize: false, innerText: marked(innerText)}
  }
}

const EDIT = "EDIT"
const RESIZE = "RESIZE"
const createUpdateAction = (text) => {
 // console.log("creating an action updateText")
  return {
    type: EDIT,
    text
  }
}
const createResizeAction = (id, fullSize) =>{ 
  return {
    type: RESIZE,
    id, 
    fullSize
  }
}
const messageReducer = (state=defaultState, action)=>{
 //  console.log("observed action " + action.type)
    let holder = {...state}
    switch (action.type){  
        case EDIT:
          holder.windows.editor.innerText = action.text;
          holder.windows.preview.innerText = marked(action.text)
          
          //console.log('observed edit')
          break;
        case RESIZE:
          
          holder.windows[action.id].fullSize = !holder.windows[action.id].fullSize
          holder.windows.fullSize = !holder.windows.fullSize
         // console.log("observed a resize event id:" + action.id + " action.fullSize")
          break;
        default:

    }
    return holder;
}
const store = createStore(messageReducer)
// END SETUP for Redux

/** SEtting up the WindowComponent**/
const WindowHeader = (props) => {
  return(
       <div className="windowHeader" >
          <div className="leftWindowHeader">{props.name} {props.testProp}</div>
          <div className="rightWindowHeader"> 
            <a href="#" style={{color:"black"}} onClick={props.sizeCallback}>{!props.fullScreen?<MaximizeIcon />:<MinimizeIcon />}</a>
          </div>
       </div>
  )
}
const EditorTextArea = connect(
  state => ({text: state.windows.editor.innerText}),
  dispatch => ({
    update: (event) => {

      dispatch ({type: EDIT, text: event.target.value})
    }
  })
)((props) => {

 // console.log("in editor text area render")
  return (
    <textarea id="editor" onChange={props.update} value={props.text}  className="windowDisplay">

    </textarea>
  )
});

const PreviewArea = connect(
  state => ({text: state.windows.preview.innerText}),
  null
)((props) => {

 // console.log("updating the prview area: ")
  let rawMarkup = {
    __html: props.text
  }
  //
  return (
    <div id="preview" dangerouslySetInnerHTML={rawMarkup} className="windowDisplay">
    </div>
  )
});
class WindowComponent extends React.Component{

  constructor(props){
    super(props)
    //console.log(JSON.stringify(props))
    this.state = {
      width: 'col-md-' + props.screen.width,
      minimizeWidth: props.screen.width,
      input: "",
      fullScreen: props.screen.fullSize
    }

    this.sizeCallback = this.sizeCallback.bind(this)
    this.hide = this.hide.bind(this)
    this.show = this.show.bind(this)
  }

  hide(){
    this.css('display', 'none')
  }
  show(){
   // console.log("showing " )
   // console.log(this.props.id)
    this.css('display', 'inline-block')
  }
  

  sizeCallback(event){
    
  //  console.log("sizeCallback in window component.")
    if(this.state.fullScreen){

      this.props.resizeWindow(this.props.id, this.minimizeWidth)
    }else{

      this.props.resizeWindow(this.props.id, 12)
    }

  }
  
  render(){
    //console.log("in windowCompoent render")
     return(
       <div className={this.props.styleClass} >
          <div className="windowFrame">
            <WindowHeader name={this.props.name} sizeCallback={this.sizeCallback} fullScreen={this.state.fullScreen} testProp={this.props.testProp}/>
            {this.props.display}
          </div>

       </div>
     )
  }
}
WindowComponent = connect(
  function mapStateToProps(state, ownProps){
   // console.log("mapping state to props for window components  " + ownProps.id)
    let fullSize = state.windows[ownProps.id].fullSize
    //   console.log("width is  " + state.windows[ownProps.id].width)

    let styleClass = ""
    if(!state.windows.fullSize){
      styleClass = "window col-md-" + state.windows[ownProps.id].width
    }else{
      if(fullSize){
        styleClass = "window col-md-12"
      }else{
        styleClass = "window windowHide"
      }
    }

    
    let toReturn = {
      width: state.windows[ownProps.id].width,
      fullSize: fullSize,
      styleClass: styleClass
    }
    return toReturn
  },
  function mapDispatchToProps(dispatch){
    return{
      resizeWindow: (id, width) => {
        dispatch(createResizeAction(id, width))
      }
    }
  }, null,  {forwardRef: true}
)(WindowComponent)

class App extends React.Component{
  constructor(props){
    super(props)
    this.state ={
      
    }
    this.editorRef = React.createRef();
    this.previewRef = React.createRef();

  }
  


  render(){

    //console.log("render for app")
    return (
        <div className="outerDiv ">         
        <div className="row" style={{height: "100%", margin: 0}}>
            <WindowComponent screen={this.props.editor} name="Editor" id='editor' ref={this.editorRef} display={<EditorTextArea />} />
            <WindowComponent screen={this.props.preview} name="Preview" id='preview' ref={this.previewRef} display={<PreviewArea />} />
          </div>
        </div>
    )
  }
}
const AppContainer = connect(
  function mapState(state){


    var toReturn = {
      editor: state.windows.editor,
      preview: state.windows.preview
    }

    return toReturn
  },
  function mapDispatches(dispatch){
    return {
      updateText: (text) => {
        dispatch(createUpdateAction(text))
      }
    }
  }
)(App)

      
render(
    <Provider store={store}>
         <AppContainer />
    </Provider>,
  document.getElementById('App')
 )

 
              
            
!
999px

Console