New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mdast-util-math

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-math

mdast extension to parse and serialize math

3.0.0
latest
Source
npm
Version published
Weekly downloads
549K
-14.87%
Maintainers
2
Weekly downloads
 
Created

What is mdast-util-math?

The `mdast-util-math` package is a utility for working with math content in Markdown Abstract Syntax Trees (MDAST). It provides tools to parse and serialize math content, making it easier to handle mathematical expressions within Markdown documents.

What are mdast-util-math's main functionalities?

Parse Math Content

This feature allows you to parse Markdown content that includes inline and block math expressions. The code sample demonstrates how to use `mdast-util-math` with `remark-parse` and `remark-math` to parse a Markdown string containing a math expression.

const { fromMarkdown } = require('mdast-util-math');
const { unified } = require('unified');
const markdown = require('remark-parse');
const math = require('remark-math');

const processor = unified()
  .use(markdown)
  .use(math);

const tree = processor.parse('Here is some math: $E=mc^2$');
console.log(tree);

Serialize Math Content

This feature allows you to serialize MDAST containing math expressions back into Markdown. The code sample shows how to convert an MDAST tree with an inline math node back into a Markdown string.

const { toMarkdown } = require('mdast-util-math');
const { unified } = require('unified');
const markdown = require('remark-stringify');
const math = require('remark-math');

const tree = {
  type: 'root',
  children: [
    { type: 'paragraph', children: [
      { type: 'text', value: 'Here is some math: ' },
      { type: 'inlineMath', value: 'E=mc^2' }
    ]}
  ]
};

const processor = unified()
  .use(markdown)
  .use(math);

const result = processor.stringify(tree);
console.log(result);

Other packages similar to mdast-util-math

Keywords

unist

FAQs

Package last updated on 16 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts