React renderer for CommonMark (rationalized Markdown)
Branch: master
Clone or download
Pull request Compare This branch is 92 commits behind rexxars:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src
test
.editorconfig
.eslintignore
.eslintrc
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
package.json

README.md

commonmark-react-renderer

npm versionBuild StatusCoverage StatusCode Climate

Renderer for CommonMark which returns an array of React elements, ready to be used in a React component. See react-markdown for such a component.

Installing

npm install --save commonmark-react-renderer

Basic usage

var CommonMark = require('commonmark');
var ReactRenderer = require('commonmark-react-renderer');

var parser = new CommonMark.Parser();
var renderer = new ReactRenderer();

var input = '# This is a header\n\nAnd this is a paragraph';
var ast = parser.parse(input);
var result = renderer.render(ast);

// `result`:
[
    <h1>This is a header</h1>,
    <p>And this is a paragraph</p>
]

Options

Pass an object of options to the renderer constructor to configure it. Available options:

  • sourcePos - boolean Setting to true will add data-sourcepos attributes to all elements, indicating where in the markdown source they were rendered from (default: false).
  • escapeHtml - boolean Setting to true will escape HTML blocks, rendering plain text instead of inserting the blocks as raw HTML (default: false).
  • skipHtml - boolean Setting to true will skip inlined and blocks of HTML (default: false).
  • softBreak - string Setting to br will create <br> tags instead of newlines (default: \n).

Testing

git clone git@github.com:rexxars/commonmark-react-renderer.git
cd commonmark-react-renderer
npm install
npm test

License

MIT-licensed. See LICENSE.