mdast utility to parse and serialize inline math (:math[...])
npm install mdast-util-math-inlinemdast utilities for inline math (:math[...]).
``bash`
npm install mdast-util-math-inline
`javascript
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()]
})
`
`typescript`
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.
When serializing to markdown:
- ] is escaped as \]\
- before ] or \ is escaped as \\`
- Balanced brackets don't need escaping
MIT