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.
npm:
npm install mdast-util-math
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
$$
Note: the separate extensions are also available at
mdast-util-math/from-markdown
andmdast-util-math/to-markdown
.
Support math.
These exports are extensions, respectively for
mdast-util-from-markdown
and
mdast-util-to-markdown
.
remarkjs/remark
— markdown processor powered by pluginsremarkjs/remark-math
— remark plugin to support mathmicromark/micromark
— the smallest commonmark compliant markdown parser that existsmicromark/micromark-extension-math
— micromark extension to parse mathsyntax-tree/mdast-util-from-markdown
— mdast parser usingmicromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdast
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.