Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-remark
Advanced tools
react-remark offers a React hook and React component based way of rendering markdown into React using remark
npm
npm install --save react-remark
yarn
yarn add react-remark
import React, { useEffect } from 'react';
import { useRemark } from 'react-remark';
const ExampleComponent = () => {
const [reactContent, setMarkdownSource] = useRemark();
useEffect(() => {
setMarkdownSource('# markdown header');
}, []);
return reactContent;
};
export default ExampleComponent;
import React from 'react';
import { useRemark } from 'react-remark';
const ExampleComponent = () => {
const [reactContent, setMarkdownSource] = useRemark();
return (
<>
<input
type="text"
onChange={({ currentTarget }) => setMarkdownSource(currentTarget.value)}
/>
{reactContent}
</>
);
};
export default ExampleComponent;
import React from 'react';
import { useRemarkSync } from 'react-remark';
const ExampleComponent = () => {
const reactContent = useRemarkSync('# markdown header');
return reactContent;
};
export default ExampleComponent;
:notebook: Note that some remark plugins are async, these plugins will error if used with useRemarkSync
.
More examples of usage as hook in storybook.
import React, { useState } from 'react';
import { Remark } from 'react-remark';
const ExampleComponent = () => (
<Remark>{`
# header
1. ordered
2. list
`}</Remark>
);
export default ExampleComponent;
import React, { useState } from 'react';
import { Remark } from 'react-remark';
const ExampleComponent = () => {
const [markdownSource, setMarkdownSource] = useState('');
return (
<>
<input
type="text"
onChange={({ currentTarget }) => setMarkdownSource(currentTarget.value)}
/>
<Remark>{markdownSource}</Remark>
</>
);
};
export default ExampleComponent;
More examples of usage as component in storybook.
A set of runnable examples are provided through storybook at https://remarkjs.github.io/react-remark. The source for the story files can be found in /stories.
react-remark
+---------------------------------------------------------------------------------------------------------------------------------------------+
| |
| +----------+ +----------------+ +---------------+ +----------------+ +--------------+ |
| | | | | | | | | | | |
| -markdown->+ remark +-mdast->+ remark plugins +-mdast->+ remark-rehype +-hast->+ rehype plugins +-hast->+ rehype-react +-react elements-> |
| | | | | | | | | | | |
| +----------+ +----------------+ +---------------+ +----------------+ +--------------+ |
| |
+---------------------------------------------------------------------------------------------------------------------------------------------+
relevant links: markdown, remark, mdast, remark plugins, remark-rehype, hast, rehype plugins, rehype-react
remarkParseOptions
(Object) - configure how Markdown is parsed, same as remark-parse
optionsremarkPlugins
(Array) - remark plugins or custom plugins to transform markdown content before it is translated to HTML (hast)remarkToRehypeOptions
(Object) - configure how Markdown (mdast) is translated into HTML (hast), same as remark-rehype
optionsrehypePlugins
(Array) - rehype plugins or custom plugins to transform HTML (hast) before it is translated to React elements.rehypeReactOptions
(Object) - configure how HTML (hast) is translated into React elements, same as rehype-react
optionsimport React, { Fragment } from 'react';
import { useRemark } from 'react-remark';
import remarkGemoji from 'remark-gemoji';
import rehypeSlug from 'rehype-slug';
import rehypeAutoLinkHeadings from 'rehype-autolink-headings';
// ...
const [reactContent, setMarkdownSource] = useRemark({
remarkPlugins: [remarkGemoji],
remarkToRehypeOptions: { allowDangerousHtml: true },
rehypePlugins: [rehypeSlug, rehypeAutoLinkHeadings],
rehypeReactOptions: {
components: {
p: (props) => <p className="custom-paragraph" {...props} />,
},
},
});
import React, { Fragment } from 'react';
import { Remark } from 'react-remark';
import remarkGemoji from 'remark-gemoji';
import rehypeSlug from 'rehype-slug';
import rehypeAutoLinkHeadings from 'rehype-autolink-headings';
// ...
<Remark
remarkPlugins={[remarkGemoji]}
remarkToRehypeOptions={{ allowDangerousHtml: true }}
rehypePlugins={[rehypeSlug, rehypeAutoLinkHeadings]}
rehypeReactOptions={{
components: {
p: (props) => <p className="custom-paragraph" {...props} />,
},
}}
>
{markdownSource}
</Remark>;
FAQs
Renders Markdown as React components
The npm package react-remark receives a total of 20,227 weekly downloads. As such, react-remark popularity was classified as popular.
We found that react-remark demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.