Skip to content

Instantly share code, notes, and snippets.

@lordmalvern
Created January 25, 2017 02:30
Show Gist options
  • Save lordmalvern/93b66642362bf92ed44950222148c8f7 to your computer and use it in GitHub Desktop.
Save lordmalvern/93b66642362bf92ed44950222148c8f7 to your computer and use it in GitHub Desktop.
Zipline Markdown Previewer
<div id="content">
</div>
var MarkdownBox = React.createClass({
getInitialState: function() {
return {
text: 'Hello World!\n======\n2nd heading \n-------\n\n### Subheading'
};
},
changeText: function(e) {
this.setState({
text: e.target.value
});
},
render: function() {
return ( <div>
<
textarea value = {
this.state.text
}
onChange = {
this.changeText
}
/> <
MarkdownPreview data = {
this.state.text
}
/> </div>
);
}
});
var MarkdownPreview = React.createClass({
markup: function() {
var raw = marked(this.props.data, {
sanitize: true
});
return {
__html: raw
};
},
render: function() {
return ( < div className = "markdownPreview" >
<
span dangerouslySetInnerHTML = {
this.markup()
}
/></div>
)
}
});
//ReactDOM.render(<h1>Hello world!</h1>, document.getElementById('content'));
ReactDOM.render( < MarkdownBox / > , document.getElementById('content'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
$maxwidth: 600px
$maxheight: 400px
textarea
width: $maxwidth
height: $maxheight
.markdownPreview
display: inline-block
float: right
width: $maxwidth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment