Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sibiraj-s/marked-react
⚛️ Render Markdown as React components
https://github.com/sibiraj-s/marked-react
markdown markedjs react react-markdown
Last synced: about 6 hours ago
JSON representation
⚛️ Render Markdown as React components
- Host: GitHub
- URL: https://github.com/sibiraj-s/marked-react
- Owner: sibiraj-s
- License: mit
- Created: 2021-10-27T03:20:20.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T01:56:06.000Z (about 2 months ago)
- Last Synced: 2024-11-04T00:33:19.886Z (9 days ago)
- Topics: markdown, markedjs, react, react-markdown
- Language: TypeScript
- Homepage: https://sibiraj-s.github.io/marked-react/
- Size: 4.88 MB
- Stars: 68
- Watchers: 3
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# marked-react
> Render Markdown as React components using [marked].
[![Tests](https://github.com/sibiraj-s/marked-react/actions/workflows/tests.yml/badge.svg)](https://github.com/sibiraj-s/marked-react/actions/workflows/tests.yml)
[![Version](https://badgen.net/npm/v/marked-react)](https://npmjs.com/marked-react)
[![License](https://badgen.net/npm/license/marked-react)](https://github.com/sibiraj-s/marked-react/blob/master/LICENSE)## TL;DR
- Uses [marked](https://marked.js.org/) to parse markdown
- Renders actual react elements instead of using `dangerouslySetInnerHTML`
- HTML in markdown is rendered as plain text[Demo]
## Installation
```bash
$ npm i marked-react
```## Usage
```js
import ReactDOM from 'react-dom';
import Markdown from 'marked-react';const domContainer = document.getElementById('root');
const root = ReactDOM.createRoot(domContainer);
root.render(# Hello world!);
```### Component Props
- **value**[`string`] - Markdown content.
- **baseURL** [`string`] - A prefix url for any relative link.
- **openLinksInNewTab** [`boolean`] - Attribute `target=_blank` will be added to link elements
- **langPrefix** [`string`] - A string to prefix the className in a `` block. Useful for syntax highlighting. Defaults to `language-`.
- **breaks** [`boolean`] - Add `br` tag on single line breaks. Requires `gfm` to be `true`
- **gfm** [`boolean`] - Use approved [Github Flavoured Markdown](https://github.github.com/gfm/)
- **isInline**[`boolean`] - Parse [inline](https://marked.js.org/using_advanced#inline) markdown.## Syntax highlight code blocks
An example with [react-lowlight]
```js
import ReactDOM from 'react-dom';
import Markdown from 'marked-react';
import Lowlight from 'react-lowlight';
import javascript from 'highlight.js/lib/languages/javascript';Lowlight.registerLanguage('js', javascript);
const renderer = {
code(snippet, lang) {
return ;
},
};const markdown = 'console.log("Hello world!")';
const domContainer = document.getElementById('root');
const root = ReactDOM.createRoot(domContainer);
root.render();
```Some awesome options available to highlight code
- [react-syntax-highlighter]
- [react-lowlight]
- [react-refractor][marked]: https://marked.js.org/
[demo]: https://sibiraj-s.github.io/marked-react/
[react-lowlight]: https://github.com/rexxars/react-lowlight
[react-refractor]: https://github.com/rexxars/react-refractor
[react-syntax-highlighter]: https://github.com/react-syntax-highlighter/react-syntax-highlighter