123

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
 
    
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
    <title>Build a Markdown Previewer</title>
  </head>
  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root"></div>
   
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
  </body>

            
          
!
            
              body {
  line-height: 1.5em;
  background-color: #eaf8bf;
  text-align:center;
 
}

$yellow-color:#eaf8bf;
$dark-blue-color:#114b5f;
$lighter-blue-color:#456990;
$turquoise-like-color:#028090;
$grey-color:#686868;


.App {
  display: grid;
  grid-template-columns: 1;
  grid-template-rows: 4;
  grid-template-areas: 'header' 'editor' 'viewer' 'footer1';
  grid-gap: 10px;
}

header>h1 {
  color:$dark-blue-color;
}

label {
  text-align:justify;
  position:relative;
  display:block;
  background-color:$dark-blue-color;
  background-size:cover;
  color:$yellow-color;
  margin:0;
}

#editorBoxLabel:after{
  content:" \2193";
}

#editor {
  width: 100%;
  height: 100%;
  min-height: 18em;
  margin-top:-1.8em;
  box-sizing:border-box;
 }

 #editorBox{
  width: 100%;
  min-height: 15em;
  border: solid;
  border-color: $grey-color;
  box-sizing: padding-box;
 }

#previewBox {
  background-color: $lighter-blue-color;
  border: solid;
  border-color: $grey-color;
}

#preview {
  text-align: left;
  margin-left: 3px;
  color:$yellow-color;
  a{
    color:$dark-blue-color;
  }
}

@media screen and (min-width:800px) {
  .App {
    grid-template-columns: 1fr 2fr;
    grid-template-rows: 3;
    grid-template-areas: 'header header' 'editor viewer' 'footer1 footer1';
  }
  header {
    grid-area: header;
  }
  #editorBox {
    grid-area: editor;
    }
  #previewBox {
    grid-area: viewer;
  }
  #editor{
    margin-top:0px;
    height:98.5%;
 
  }
}


table, td, th {
  border:solid;
  border-width:2px;
  border-color:$yellow-color;
}

blockquote p{
  border-left:solid 2px $yellow-color;
  }

  pre, code{
    background-color:$turquoise-like-color;
  }

#footerInReact {
  text-align: center;
  border-top: 1px solid rgb(53, 53, 63);
  max-height: max-content;
  grid-area: footer1;
  margin-top: -10px;

    p{
      font-size:1em;
    }
    a img {
      height:2.5em;
      margin-bottom: -0.2em;
    }
}

            
          
!
            
              //index.js
//import React from 'react';
//import ReactDOM from 'react-dom';
//import {Provider} from 'react-redux';
const { createStore, applyMiddleware,combineReducers } = Redux;
const { Provider, connect } = ReactRedux
const thunk = ReduxThunk.default



//constants.js
const NEWTEXT='NEWTEXT';

const footer=`
<footer>
<h5 class="textcenter">Made by
                <a href="https://www.ionvarsescu.tk" target="_blank">Ion Varsescu</a>
        </h5>
<section id="contact">
  <a href="https://www.facebook.com/varsescu.ion" target="_blank">
    <i class="fa fa-facebook-square fa-3x"></i>
  </a>
  <a href="https://twitter.com/IonVcoding" target="_blank">
    <i class="fa fa-twitter fa-3x"></i>
  </a>
  <a href="https://www.linkedin.com/in/ionvarsescu/" target="_blank">
    <i class="fa fa-linkedin fa-3x"></i>
  </a>
  <a href="https://plus.google.com/100730160336168112160" target="_blank">
    <i class="fa fa-google-plus fa-3x"></i>
  </a>
  <a href="https://github.com/Nei-V" target="_blank">
    <i class="fa fa-github fa-3x"></i>
  </a>
  <a href="https://www.freecodecamp.org/portofolio/nei-v" target="_blank">
    <img src="https://res.cloudinary.com/dg45lvfuu/image/upload/v1465845327/fcc-app-icon_gqbnku.png" />
  </a>
</section>
</footer>`

//action1.js
const allText = (text) => dispatch => {
    console.log("text in action1 alltext : ",text);
    dispatch ({
        type: NEWTEXT,
        fullText: text
    })
}


//reducer1.js
let a=`# 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;
  }
}

\`\`\`
<b>bold</b>  

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)`;

const showText = (state = a,action) => {
    switch (action.type) {
        case NEWTEXT:
        console.log("new state");
        console.log("fullText after dispatch",action.fullText);
        return action.fullText;
        default:
        console.log("old state");
        return state;
    }
}
console.log("showText in reducer ",showText);

//rootreducers
//import {combineReducers} from 'redux';

const rootReducer=combineReducers({
    showText
})


//app.js
//import React, { Component } from 'react';
//import './App.css';
//import { connect } from 'react-redux';
//import { allText } from './actions/action1';
//import marked from 'marked';
//import { footer } from './constants';

class Footer extends React.Component {


  render() {
    function createFooter(a) {
      return { __html: a }
    }
    return (
      <div id="footerInReact" dangerouslySetInnerHTML={createFooter(footer)}>
      </div>
    )
  }
};

class App extends React.Component {
  constructor(props) {
    super(props);
    //this.state=this.props.input;
    //version 2:the line above is not needed because I update fields directly from Redux - dumb component
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event) {
    console.log("event value in handlechange: ", event.target.value);
    /*
     this.setState({
       showText:this.state.input,
     })
      version 2: this.setState - is not needed  because I update fields directly from Redux   */
    this.props.submitNewInput(event.target.value);
  }

  render() {

    //in markdown, open a link in a new window
    const renderer = new marked.Renderer();
    const linkRenderer = renderer.link;
    renderer.link = (href, title, text) => {
      const html = linkRenderer.call(renderer, href, title, text);
      return html.replace(/^<a /, '<a target="_blank" rel="nofollow" ');
    };

    marked.setOptions({
      tables: true,
      gfm: true,
      breaks: true,
    })

    let d = marked(this.props.input.showText, { renderer });

    function createMarkup(a) {
      return { __html: a }
    }

    return (
      <div className="App">
        <header>
          {/*<img src={logo} className="App-logo" alt="logo" />*/}
          <h1>Markdown Previewer</h1>
        </header>
        <div id="editorBox">
        <label id="editorBoxLabel">Write markdown here:</label>
          <textarea id="editor" value={this.props.input.showText} onChange={this.handleChange} autoFocus />
          {/*version 2: in line above value={this.state.showText} if I update field from React*/}
        </div>
        <div id="previewBox">
        <label id="previewBoxLabel">This is how it looks:</label>
          <div id="preview" dangerouslySetInnerHTML={createMarkup(d)} />
        </div>
        {/*version 2: in line above {this.state.showText} instead if I update field from React*/}
        <Footer />
      </div>
    );
  }
};

const mapStateToProps = (state) => {
  return { input: state }
}

const mapDispatchToProps = (dispatch) => {
  return {
    submitNewInput: (text) => {
      console.log("text in mapDispatch: ", text);
      dispatch(allText(text))
    }
  }
}

const Container = connect(mapStateToProps, mapDispatchToProps)(App);


//store.js
//import {createStore,applyMiddleware} from 'redux';
//import thunk from 'redux-thunk';


const reduxStore = createStore(rootReducer,applyMiddleware(thunk));


ReactDOM.render(
<Provider store={reduxStore}>
<Container />
</Provider>, document.getElementById('root'));



            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console