1.0.1 • Published 8 years ago

react-rich-markdown v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

react-rich-markdown

A ready-to-go component to render rich Markdown snippets.


The <Markdown /> component renders the contents of its source property with markdown-it and the following plugins:

Usage

import React from 'react';
import Markdown from 'react-rich-markdown';

export class MyComponent extends React.Component {
	render() {
		const opts = { smartarrows: false };
		return (
			<div>
				<h1>{this.props.sometitle}</h1>
				<Markdown source={this.props.sometext} options={opts}/>
			</div>
		);
	}
}

The options property allows to switch off unneeded plugins

{
	"sup": true|false,
	"sub": true|false,
	"smartarrows": true|false,
	/* syntax highlighting */
	"sh": true|false,
	"math": true|false
}

By default all the plugins are loaded.

Styling

The component includes a stylesheet for LaTex expressions and syntax highlighting. It's a very big file because it has all the fonts needed by Katex inlined, so you can setup it quickly with PostCSS or Webpack.

Nonetheless, I strongly recommend to not use this solution in production, and instead go and download Katex styles separately, without the fonts inlined, so the browser isn't forced to download them all at once.

You'll need also Highlight.js styles.

TODOs

  1. Testing
  2. Support mounting other markdown-it plugins

License

ISC