
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
commonmark-react-object-renderer
Advanced tools
Renderer for CommonMark which returns a React description object
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.
import { Parser } from 'commonmark';
import Renderer from 'commonmark-react-object-renderer';
const parser = new Parser();
const renderer = new Renderer();
const input = `
# This is a header
And this is a paragraph
`;
const ast = parser.parse(input);
const result = renderer.render(ast);
assert.deepStrictEqual(result, {
type: 'div',
children: [
{
type: 'h1',
children: ['This is a header'],
},
{
type: 'p',
children: ['And this is a paragraph'],
},
],
});
Each instance of Renderer has these methods:
render(ast)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. new Renderer(options).
renderersThis object should contain properties named after the possible node types as returned by the commonmark parser.
Those include: block_quote, code_block, code, document, emph, heading, html_block, html_inline, image, item, linebreak, link, list, paragraph, softbreak, strong, text, thematic_break.
Each property should be a function that takes two arguments, in the following order:
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.
FAQs
Renderer for CommonMark which returns a React description object
We found that commonmark-react-object-renderer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.