Renderer for CommonMark which returns a React description object
This renders a "description" of a React element which can be then used for rendering, e.g. with react-from-object. It's especially useful for passing rendered markdown from server to the client.
;;const parser = ;const renderer = ;const input = `# This is a headerAnd this is a paragraph`;const ast = parser;const result = renderer;assert;
Each instance of
Renderer has these methods:
Returns the rendered markdown in the React element "description" format.
The first argument should be the ast as returned by the commonmark parser.
Options can be passed as the first argument to the
Renderer constructor, e.g.
This object should contain properties named after the possible node types as returned by the commonmark parser.
Each property should be a function that takes two arguments, in the following order:
- The node, as returned by the commonmark parser (for possible properties please refer to the documentation)
- The newly created element in an initial (empty) state
Those functions should return the rendered element, which can be either the modified second argument or a completely new object.
For an example usage please refer to the tests.
Copyright (c) 2017 Rafał Ruciński. Licensed under the MIT license.