Skip to content

syntax-tree/mdast-util-math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 7, 2020
a63c761 · Oct 7, 2020

History

2 Commits
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020

Repository files navigation

mdast-util-math

Build Coverage Downloads Size Sponsors Backers Chat

Extension for mdast-util-from-markdown and/or mdast-util-to-markdown to support math in mdast. When parsing (from-markdown), must be combined with micromark-extension-math.

You probably shouldn’t use this package directly, but instead use remark-math with remark.

Install

npm:

npm install mdast-util-math

Use

Say we have the following file, example.md:

Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation.

$$
L = \frac{1}{2} \rho v^2 S C_L
$$

And our script, example.js, looks as follows:

var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-math')
var math = require('mdast-util-math')

var doc = fs.readFileSync('example.md')

var tree = fromMarkdown(doc, {
  extensions: [syntax],
  mdastExtensions: [math.fromMarkdown]
})

console.log(tree)

var out = toMarkdown(tree, {extensions: [math.toMarkdown]})

console.log(out)

Now, running node example yields (positional info removed for brevity):

{
  type: 'root',
  children: [
    {
      type: 'paragraph',
      children: [
        {type: 'text', value: 'Lift('},
        {type: 'inlineMath', value: 'L', data: {/* … */}},
        {type: 'text', value: ') can be determined by Lift Coefficient ('},
        {type: 'inlineMath', e: 'C_L', data: {/* … */}},
        {type: 'text', value: ') like the following equation.'}
      ]
    },
    {type: 'math', meta: null, value: 'L = \\frac{1}{2} \\rho v^2 S C_L', data: {/* … */}}
  ]
}
Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation.

$$
L = \frac{1}{2} \rho v^2 S C_L
$$

API

math.fromMarkdown

math.toMarkdown

Note: the separate extensions are also available at mdast-util-math/from-markdown and mdast-util-math/to-markdown.

Support math. These exports are extensions, respectively for mdast-util-from-markdown and mdast-util-to-markdown.

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer