mdast-util-math-inline
v1.0.0
Published
mdast utility to parse and serialize inline math (:math[...])
Maintainers
Readme
mdast-util-math-inline
mdast utilities for inline math (:math[...]).
Install
npm install mdast-util-math-inlineUsage
import { fromMarkdown } from 'mdast-util-from-markdown'
import { toMarkdown } from 'mdast-util-to-markdown'
import { mathInline } from 'micromark-extension-math-inline'
import { mathInlineFromMarkdown, mathInlineToMarkdown } from 'mdast-util-math-inline'
// Parse
const tree = fromMarkdown(':math[x^2]', {
extensions: [mathInline()],
mdastExtensions: [mathInlineFromMarkdown()]
})
// Stringify
const md = toMarkdown(tree, {
extensions: [mathInlineToMarkdown()]
})AST
InlineMath
interface InlineMath extends Literal {
type: 'inlineMath'
value: string
data?: {
hName: 'code'
hProperties: { className: ['language-math', 'math-inline'] }
hChildren: [{ type: 'text', value: string }]
}
}The data fields enable compatibility with remark-rehype and rehype-katex.
Escaping
When serializing to markdown:
]is escaped as\]\before]or\is escaped as\\- Balanced brackets don't need escaping
License
MIT
