Skip to content

Instantly share code, notes, and snippets.

@iksena
Created May 7, 2020 16:23
Show Gist options
  • Save iksena/65e6e403354f5fe7613138cf571b9603 to your computer and use it in GitHub Desktop.
Save iksena/65e6e403354f5fe7613138cf571b9603 to your computer and use it in GitHub Desktop.
react-katex
import React from 'react';
import ReactMarkdown from 'react-markdown';
import RemarkMathPlugin from 'remark-math';
import { BlockMath, InlineMath } from 'react-katex';
import 'katex/dist/katex.min.css';
const _mapProps = (props) => ({
...props,
escapeHtml: false,
plugins: [
RemarkMathPlugin
],
renderers: {
...props.renderers,
math: ({ value }) => <BlockMath>{value}</BlockMath>,
inlineMath: ({ value }) => <InlineMath>{value}</InlineMath>
}
});
const Markdown = (props) => <ReactMarkdown {..._mapProps(props)} />;
export default Markdown;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment