Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
commonmark-react-object-renderer
Advanced tools
Readme
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)
.
renderers
This 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
The npm package commonmark-react-object-renderer receives a total of 2 weekly downloads. As such, commonmark-react-object-renderer popularity was classified as not popular.
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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.