$ cnpm install markdown-to-react-components
Convert markdown into react components
There are several projects that claims to convert markdown using React, but that is not exactly right. They produce one single React component with some plain markdown converted HTML in it. They do not produce React components of the markdown syntax. But this project does!
npm install markdown-to-react-components
import React from 'react';
import MTRC from 'markdown-to-react-components';
MTRC.configure({
h1: React.createClass({
render() {
return <h1 id={this.props.id} style={{color: 'red'}}>{this.props.children}</h1>
}
})
});
const Editor = React.createClass({
getInitialState() {
return {
content: null
};
},
onTextareaChange(event) {
this.setState({
content: MTRC(event.target.value).tree
});
},
render() {
return (
<div>
<div>{this.state.content}</div>
<textarea onChange={this.onTextareaChange}/>
</div>
);
}
});
export default Editor;
You will have to include the Prism.js library and its css manually in your project. Look in the example app to see how this is done.
```javascript
var foo = 'bar';
```
```html
<h1>Hello world!</h1>
```
Supported languages can be found over at prism.js.
Allows you to configure custom elements for your markdown.
MTRC.configure({
h1: React.createClass({
render() {
return <h1 style={{color: 'red'}}>{this.props.children}</h1>
}
})
});
MTRC('# Hello there').tree // React virtual dom tree
MTRC('# Hello there').toc // [{children: [], level: 1, title: 'Hello there', id: 'hello-there'}]
npm installnpm starthttp://localhost:8080/webpack-dev-server/bundleCopyright 2013 - present © cnpmjs.org | Home |