0.1.3 • Published 7 years ago

react-mathdown v0.1.3

Weekly downloads
16
License
-
Repository
-
Last release
7 years ago

react-mathdown

A configurable React Component which supports rendering math in the Markdown

Table of Contents

Usage

1. Install

npm i -S react-mathdown
// or
yarn add react-mathdown

2. Add MathJax to your current project

Add a script tag to your index.html like this:

<script
  type="text/javascript"
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML-full">
</script>

3. Let's rock!

import React, { Component } from 'react'
import MathDown from 'react-mathdown'

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: '**golden ratio**: $\\frac{\\sqrt{5}+1}{2}$'
    }
  }

  onChange = (e) => this.setState({value: e.target.value})

  render() {
    return (
      <div>
        <input
          value={this.state.value}
          style={{ width: 300 }}
          onChange={this.onChange}
        />
        <MathDown value={this.state.value} />
      </div>
    )
  }
}

export default App

Configuration

PropertyDescriptionTypeDefault
stylestyle object of containerobject-
classNameclass name of containerstring-
jaxConfigMathJax.Hub.configobject{ tex2jax: { inlineMath: ['$', '$'] } }
markedConfigmarked optionsobject{ gfm: true, tables: true, breaks: false, smartLists: true, smartypants: false }
valuemarkdown text to be renderedstring

NOTE:

  • props.jaxConfig and props.markedConfig will be merged with the default value and passed to MathJax.Hub.Config() and marked.setOptions() respectively.
  • markedConfig.sanitize will always be false, since we do MathJax before marked.
0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago