
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
rich-content
Advanced tools
Controlled Rich text for React
npm install --save rich-content
or with Yarn
yarn add rich-content
<ContentProvider /> Paramsdictionary: JSON Object or YAML string. All the text with your special markup.
YAML version
text:
bold: "**I'm Bold**"
italic: ~I'm Italic~
both: "**~I'm Both~**"
params: 'This is a parameter: %{parameter}'
links: >-
Links: [:http://www.google.com](Open in new Tab) [http://www.google.com](Open
in same Tab)
image: 'This is an image: [[https://placehold.it/300]](This is an image)'
classes: '(:red I have the .red class)!'
JSON version
export default {
text: "**I'm Bold** ~I'm Italic~ **~I'm Both~**",
params: 'This is a parameter: %{parameter}',
links:
'Links: [:http://www.google.com](Open in new Tab) [http://www.google.com](Open in same Tab)',
image: 'This is an image: [[https://placehold.it/300]](This is an image)',
classes: '(:red I have the .red class)!'
};
rules: Function that returns a dictionary of regular expressions and transformations, that you want to match from your text.
NOTE: You can use the helper createRule to define your markup.
import { createRule } from 'rich-content';
const replace = createRule('%{', '}');
const bold = createRule('**');
const italic = createRule('~');
const classes = createRule('(:', ' ') + createRule('', ')');
const link = createRule('[', ']') + createRule('(', ')');
const image = createRule('[[', ']]') + createRule('(', ')');
export default ({ params }) => ({
[replace]: (_, key = '') => params[key],
[bold]: (_, text = '') => `<strong>${text}</strong>`,
[italic]: (_, text = '') => `<em>${text}</em>`,
[classes]: (_, className = '', text = '') =>
`<span class="${className}">${text}</span>`,
[image]: (_, src = '', alt = '') => `<img src="${src}" alt="${alt}" />`,
[link]: (_, link = '', label = '') =>
link.indexOf(':') === 0
? `<a href=${link.slice(1)} target="_blank">${label}</a>`
: `<a href=${link}>${label}</a>`
});
<Content /> Paramstag: (default: div) Container HTML tag.
path: Path of the value in the dictionary. Ex. a, a.b, a.b.c[0], a.b.c[0].d.
options: (Optional) Extra options defined in your rules. Ex. { params: { parameter: 'Hi!' } }.
content({ path, options } Paramspath: Path of the value in the dictionary. Ex. a, a.b, a.b.c[0], a.b.c[0].d.
options: (Optional) Extra options defined in your rules. Ex. { params: { parameter: 'Hi!' } }.
import React, { Component } from 'react';
import { content, Content, ContentProvider } from 'rich-content';
import rules from './rules';
import dictionary from './dictionary';
export default class App extends Component {
state = { lang: 'en', dictionary: {}, error: undefined };
componentDidMount() {
this.loadDictionary(this.state.lang);
}
async loadDictionary(lang) {
const { data } = await axios.get(`./${lang}.yml`);
this.setState({ lang, dictionary: data });
}
showError = ev => {
ev.preventDefault();
this.setState({ error: content({ path: 'text.bold' }) });
};
render() {
const { lang, dictionary, error } = this.state;
return (
<ContentProvider rules={rules} dictionary={dictionary}>
<div style={{ width: 640, margin: '15px auto' }}>
<h1>Testing Rich Content</h1>
{error && (
<p className="red" dangerouslySetInnerHTML={{ __html: error }} />
)}
<button
onClick={() => this.loadDictionary(lang === 'en' ? 'es' : 'en')}
>
{lang === 'en' ? 'Cambiar a Español' : 'Change to English'}
</button>
<button onClick={this.showError}>
{lang === 'es' ? 'Mostrar error' : 'Show error'}
</button>
<div className="content">
<div>
<Content tag="span" path="text.bold" />
<Content tag="span" path="text.italic" />
<Content tag="span" path="text.both" />
</div>
<Content path="params" options={{ params: { parameter: 'Hi!' } }} />
<Content path="links" />
<Content className="v-pad" path="image" />
<Content path="classes" />
</div>
</div>
</ContentProvider>
);
}
}
MIT © Thram
FAQs
Controlled Rich text for React
We found that rich-content 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.