markdown-it-simplemath
Version:
markdown-it plugin that adds simple math support
32 lines (22 loc) • 1.47 kB
Markdown
[](https://travis-ci.org/adam-p/markdown-it-simplemath)
[](https://www.npmjs.org/package/markdown-it-simplemath)
[](https://coveralls.io/r/adam-p/markdown-it-simplemath)
# markdown-it-simplemath
This is a [markdown-it](https://github.com/markdown-it/markdown-it) plugin that adds simple math support. It is up to the caller to supply a rendering function.
**NOTE:** For fully featured math rendering, you should use [runarberg/markdown-it-math](https://github.com/runarberg/markdown-it-math). This plugin was created for a particular need to render to images. It really just passes off whatever is inside `$...$` to an external renderer.
Originally developed for use with [Markdown Here](https://github.com/adam-p/markdown-here).
## Installation
```
$ npm install markdown-it-simplemath
```
## Usage
```js
var md = require('markdown-it')();
var mathRenderer = function(mathStr) {
return '<img src="https://chart.googleapis.com/chart?cht=tx&chl={urlmathcode}" alt="{mathcode}">'
.replace(/\{mathcode\}/ig, mathcode)
.replace(/\{urlmathcode\}/ig, encodeURIComponent(mathcode));
};
md.use(require('markdown-it-simplemath'), {inlineRenderer: mathRenderer});
console.log(md.render('$x \over y$'));
```