micromark-extension-mdxjs

micromark extension to support MDX.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
micromark-extension-mdxjs
401.0.0a year ago2 years agoMinified + gzip package size for micromark-extension-mdxjs in KB

Readme

micromark-extension-mdxjs
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
micromark extension to support MDX.js. Use micromark-extension-mdxmdx instead to support MDX agnostic to JS.
This package provides the low-level modules for integrating with the micromark tokenizer but has no handling of compiling to HTML: go to a syntax tree instead.

When to use this

You should probably use this package. If you don’t need all of MDX.js, the extensions can be used separately:
— support MDX (or MDX.js) expressions
— support MDX (or MDX.js) JSX
— turn some markdown features off for MDX (or MDX.js)
— support MDX.js ESM import/exports

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install micromark-extension-mdxjs
## Use

```js
import {micromark} from 'micromark'
import {mdxjs} from 'micromark-extension-mdxjs'

const output = micromark('import a from "b"\n\na <b /> c {1 + 1} d', {
  extensions: [mdxjs()]
})

console.log(output)

Yields:
<p>a  c  d</p>

…which is rather useless: go to a syntax tree with mdast-util-from-markdownfrom-markdown and mdast-util-mdxmdast-util-mdx instead.

API

This package exports the following identifiers: mdxjs. There is no default export.

mdxjs(options?)

A function that can be called with options that returns an extension for micromark to parse MDX.js (can be passed in extensions).
options
Options are the same as for mdx-expression, mdx-jsx, and mdxjs-esm, but come predefined to support JavaScript.
options.acorn
Acorn parser to use (Acornacorn, default: acorn.Parser.extend(acornJsx())).
options.acornOptions
Options to pass to acorn (Object, default: `{ecmaVersion: 2020, sourceType: 'module'}`).
options.addResult
Whether to add an estree field to tokens with the results from acorn (boolean, default: true).

Related

— the smallest commonmark-compliant markdown parser that exists
— micromark extension to support MDX (agnostic to JS)
— micromark extension to support MDX (or MDX.js) expressions
— micromark extension to support MDX (or MDX.js) JSX
— micromark extension to support misc MDX changes
— micromark extension to support MDX.js ESM import/exports
— mdast utility to support MDX (or MDX.js)

Contribute

See contributing.md in micromark/.githubcontributing for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor