Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ npm install --save react-remarkable
```jsx
import React from 'react';
import Markdown from 'react-remarkable';
import Emoji from 'remarkable-emoji'

const MyComponent = () => (
<div>
{/* Pass Markdown source to the `source` prop */}
<Markdown source="**Markdown is awesome!**" />
<Markdown source="**Markdown is awesome! :)**" plugins={[Emoji]} />

{/* Or pass it as children */}
{/* You can nest React components, too */}
Expand All @@ -39,6 +40,7 @@ Available props:
- `options` - Hash of Remarkable options
- `source` - Markdown source. You can also pass the source as children, which allows you to mix React components and Markdown.
- `container` - Element to use as container. Defaults to `div`.
- `plugins` - Array of remarkable plugins

## Syntax Highlighting

Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Remarkable extends React.Component {

componentWillUpdate(nextProps, nextState) {
if (nextProps.options !== this.props.options) {
this.md = new Markdown(nextProps.options);
this.md = this.createMarkdown(nextProps.options, nextProps.plugins);
}
}

Expand All @@ -71,17 +71,24 @@ class Remarkable extends React.Component {

renderMarkdown(source) {
if (!this.md) {
this.md = new Markdown(this.props.options);
this.md = this.createMarkdown(this.props.options, this.props.plugins);
}

return this.md.render(source);
}

createMarkdown(options, plugins) {
return plugins.reduce((md, plugin) => {
return md.use(plugin);
}, new Markdown(options));
}
}

Remarkable.defaultProps = {
container: 'div',
contentWrapper: 'span',
options: {},
plugins: [],
};

export default Remarkable;