Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
micromark-extension-math
Advanced tools
The micromark-extension-math package is an extension for micromark, a Markdown parser, that adds support for parsing and rendering mathematical expressions written in LaTeX. This package is particularly useful for developers who need to include mathematical notation in their Markdown documents.
Inline Math
This feature allows you to include inline mathematical expressions within your Markdown content using the $...$ syntax. The code sample demonstrates how to parse and render an inline math expression.
const micromark = require('micromark');
const math = require('micromark-extension-math');
const content = 'This is an inline math expression: $E=mc^2$';
const html = micromark(content, { extensions: [math()] });
console.log(html);
Display Math
This feature allows you to include display mathematical expressions using the $$...$$ syntax. Display math is typically rendered on its own line and centered. The code sample shows how to parse and render a display math expression.
const micromark = require('micromark');
const math = require('micromark-extension-math');
const content = 'This is a display math expression: $$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$';
const html = micromark(content, { extensions: [math()] });
console.log(html);
remark-math is a plugin for remark, another Markdown processor, that adds support for parsing and rendering LaTeX math expressions. It is similar to micromark-extension-math but is used within the remark ecosystem. Both packages offer similar functionalities, but the choice depends on whether you are using micromark or remark for your Markdown processing.
markdown-it-texmath is a plugin for markdown-it, a different Markdown parser, that enables the parsing and rendering of LaTeX math expressions. Like micromark-extension-math, it supports both inline and display math. The main difference is that markdown-it-texmath is designed to work with the markdown-it parser.
micromark extension to support math ($C_L$
).
As there is no spec for math in markdown, this extension stays as close to code in text and fenced code in flow in CommonMark, but using dollar signs.
If you’re using micromark
or
mdast-util-from-markdown
, use this package.
Alternatively, if you’re using remark, use
remark-math
.
Math (text) can start with one or more dollar signs, so long as they match:
With one: $\alpha$, two: $$\beta$$, or three: $$$\gamma$$$.
This is useful, because like code, typical markdown escapes don’t work.
For dollars inside math, use more dollars around it: $$\raisebox{0.25em}{$\frac
a b$}$$.
If the math starts and ends with a space (or EOL), those are removed: $$ \$ $$.
Math (flow) starts at two or more dollars:
$$
\Delta
$$
You can hide some stuff in the meta of the opening fence (but no dollars):
$$hidden information
$$
Math that doesn’t have a closing fence, still works, like fenced code:
> $$
> this is
> all math
…but at the end of their container (block quote, list item, or document), they
are closed.
This package is ESM only:
Node 12+ is needed to use it and it must be import
ed instead of require
d.
npm:
npm install micromark-extension-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:
import fs from 'fs'
import {micromark} from 'micromark'
import {math, mathHtml} from 'micromark-extension-math'
const output = micromark(fs.readFileSync('example.md'), {
extensions: [math()],
htmlExtensions: [mathHtml()]
})
console.log(output)
Now, running node example
yields (abbreviated):
<p>Lift(<span class="math math-inline"><span class="katex">…</span></span>) like the following equation.</p>
<div class="math math-display"><span class="katex-display"><span class="katex">…</span></div>
This package exports the following identifiers: math
, mathHtml
.
There is no default export.
The export map supports the endorsed
development
condition.
Run node --conditions development module.js
to get instrumented dev code.
Without this condition, production code is loaded.
math(options?)
mathHtml(htmlOptions?)
A function to create an extension for micromark to parse math (can be passed in
extensions
) and a function that can be called to get an extension to compile
them to HTML with KaTeX (can be passed in htmlExtensions
).
options
options.singleDollarTextMath
Whether to support math (text) with a single dollar (boolean
, default:
true
).
Single dollars work in Pandoc and many other places, but often interfere with
“normal” dollars in text.
htmlOptions
Passed to katex.renderToString
.
displayMode
is overwritten by this plugin, to false
for math in text, and
true
for math in flow.
remarkjs/remark
— markdown processor powered by pluginsremarkjs/remark-math
— remark plugin using this to support mathmicromark/micromark
— the smallest commonmark-compliant markdown parser that existssyntax-tree/mdast-util-math
— mdast utility to support mathsyntax-tree/mdast-util-from-markdown
— mdast parser using micromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdastSee contributing.md
in micromark/.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.
FAQs
micromark extension to support math (`$C_L$`)
The npm package micromark-extension-math receives a total of 360,139 weekly downloads. As such, micromark-extension-math popularity was classified as popular.
We found that micromark-extension-math demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.