3.0.1 • Published 5 months ago

remark-mdx v3.0.1

Weekly downloads
1,770,562
License
MIT
Repository
github
Last release
5 months ago

remark-mdx

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to support the MDX syntax (JSX, export/import, expressions).

Contents

What is this?

This package is a unified (remark) plugin to enable the extensions to markdown that MDX adds: JSX (<x/>), export/import (export x from 'y'), and expression {{1 + 1}}. You can use this plugin to add support for parsing and serializing them.

This plugin does not handle how MDX is compiled to JavaScript or evaluated and rendered to HTML. That’s done by @mdx-js/mdx.

When should I use this?

This plugin is useful if you’re dealing with the MDX syntax and integrating with remark, rehype, and the rest of unified. Some example use cases are when you want to lint the syntax or compile it to something other that JavaScript.

If you don’t use plugins and want to access the syntax tree, you can use mdast-util-from-markdown with mdast-util-mdx.

Typically though, you’d want to move a layer up: @mdx-js/mdx. That package is the core compiler for turning MDX into JavaScript which gives you the most control. Or even higher: if you’re using a bundler (Rollup, esbuild, webpack), or a site builder (Next.js) or build system (Vite) which comes with a bundler, you’re better off using an integration: see § Integrations.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-mdx

In Deno with esm.sh:

import remarkMdx from 'https://esm.sh/remark-mdx@3'

In browsers with esm.sh:

<script type="module">
  import remarkMdx from 'https://esm.sh/remark-mdx@3?bundle'
</script>

Use

import {remark} from 'remark'
import remarkMdx from 'remark-mdx'

const file = await remark()
  .use(remarkMdx)
  .process('import a from "b"\n\na <b /> c {1 + 1} d')

console.log(String(file))

Yields:

import a from "b"

a <b/> c {1 + 1} d

API

This package exports no identifiers. The default export is remarkMdx.

unified().use(remarkMdx[, options])

Add support for MDX (JSX: <Video id={123} />, export/imports: export {x} from 'y'; and expressions: {1 + 1}).

Parameters
  • options (Options, optional) — configuration
Returns

Nothing (undefined).

Options

Configuration (TypeScript type).

Fields
  • acornOptions (AcornOptions, default: {ecmaVersion: 2024, locations: true, sourceType: 'module'}) — configuration for acorn; all fields except locations can be set
  • printWidth (number, default: Infinity) — try and wrap syntax at this width; when set to a finite number (say, 80), the formatter will print attributes on separate lines when a tag doesn’t fit on one line; the normal behavior is to print attributes with spaces between them instead of line endings
  • quote ('"' or "'", default: '"') — preferred quote to use around attribute values
  • quoteSmart (boolean, default: false) — use the other quote if that results in less bytes
  • tightSelfClosing (boolean, default: false) — do not use an extra space when closing self-closing elements: <img/> instead of <img />

Authoring

For recommendations on how to author MDX, see each corresponding readme:

HTML

MDX has no representation in HTML. Though, when you are dealing with MDX, you will likely go through hast. You can enable passing MDX through to hast by configuring remark-rehype with passThrough: ['mdxjsEsm', 'mdxFlowExpression', 'mdxJsxFlowElement', 'mdxJsxTextElement', 'mdxTextExpression'].

Syntax

For info on the syntax of these features, see each corresponding readme:

Syntax tree

For info on the syntax tree of these features, see each corresponding readme:

Errors

For info on what errors are thrown, see each corresponding readme:

Types

This package is fully typed with TypeScript. It exports the additional type Options.

If you’re working with the syntax tree, you can register the new node types with @types/mdast by adding a reference:

// Register MDX nodes in mdast:
/// <reference types="remark-mdx" />

import {visit} from 'unist-util-visit'

function myRemarkPlugin() {
  /**
   * @param {import('mdast').Root} tree
   *   Tree.
   * @returns {undefined}
   *   Nothing.
   */
  return function (tree) {
    visit(tree, function (node) {
      console.log(node) // `node` can now be one of the MDX nodes.
    })
  }
}

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, remark-mdx@^3, compatible with Node.js 16.

Security

See § Security on our website for information.

Contribute

See § Contribute on our website for ways to get started. See § Support 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.

License

MIT © Titus Wormer

@mdx-js/mdx@tonyyanga/mintlify_cli@tonyyanga/mintlify_previewing@guacson/docs@commercetools-docs/gatsby-theme-docs@open-tech-world/create-react-doc-core@ridleywinters/sea@infinitebrahmanuniverse/nolb-rema@saaspe/componentsreact-island@everything-registry/sub-chunk-2647ghedevglobal_components_assignmentm2dx-utilsimput-cmsinfinitymint-clientinject-markdownisland-hhx-devmark-cellmark-smithmarkdown-translatemdxx-parsermdx-localized-headingsmdx-next-testmdx-blogmdx-serializermdx-unified-bundlermdx-variablesmeow-cmsnext-searchnext-docs-zetamuitailwind@saschazar/next-mdx-extended@secretflow/dumi-plugin-search@storm-software/linting-tools@podlubnaja/ui-kit@tinacms/mdx@reflexjs/gatsby-plugin-search-algolia@untitled-docs/gatsby-plugin-package-changelog@silvenon/blog-utils@skeetboothppq/component-library@readme/markdown@shivarajapple/first-library@staticcms/corewritrparvan_reactjs_componentsparvan_componentspf-docstextlint-plugin-mdxsvelte-component-libtheme-patternfly-orgr-pressreact-form-component-libraryremark-preset-webprorecipextina-graphqltina-graphql-primitivessfs-componentssequelcomponentsafe-mdxvigor-moonvite-plugin-react-pagestractor-loader-mdx@active-mdx/core@alicloud/console-components-lib-documenter@aliyun-sls/vite-plugin-react-pages@adaptable/platform-remark-plugins@adamwebster/tabini@akollegger/remark-lint-play-mdx@forestryio/gql@elastic/docs-lint@hashicorp/platform-content-conformance@hashicorp/platform-remark-plugins@hashicorp/remark-plugins@hashicorp/versioned-docs@hipster/mdx2-issue-checker@maximai/fumadocs-core@lona/mdx-slate-serializer@lottiefiles/remark-preset@mintlify/common@mdx-js/language-service@octopusthink/ghost-ship@dialectik/compiler@dinhbinh1610/dm-react-markdown-editor@dinhbinh1610/mdx@blkmarketco/components-library@blizzbolts/docit@blocks/serializer@coding-poem/mdx-ast-parser@breakaway/theme-patternfly-org@breakaway/documentation-framework@carbon-platform/mdx-sanitizer@paradigmjs/scripts@pdchen/markdown-processor@patternfly/documentation-framework@7-docs/cli@beerose/semantic-search@astro-content/server@newlevelup/remark-config@neon.id/uji-grader
3.0.1

5 months ago

3.0.0

9 months ago

2.3.0

1 year ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.2

2 years ago

2.1.3

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

2.0.0-rc.2

3 years ago

2.0.0-rc.1

3 years ago

2.0.0-ci.50

3 years ago

2.0.0-ci.43

3 years ago

2.0.0-ci.42

3 years ago

2.0.0-ci.40

3 years ago

2.0.0-ci.39

3 years ago

2.0.0-ci.35

3 years ago

2.0.0-ci.18

3 years ago

2.0.0-ci.4

3 years ago

2.0.0-next.9

3 years ago

1.6.22

4 years ago

1.6.20

4 years ago

1.6.21

4 years ago

1.6.19

4 years ago

2.0.0-next.8

4 years ago

1.6.18

4 years ago

1.6.17

4 years ago

2.0.0-next.7

4 years ago

1.6.15

4 years ago

1.6.16

4 years ago

2.0.0-next.6

4 years ago

2.0.0-next.5

4 years ago

2.0.0-next.4

4 years ago

1.6.14

4 years ago

1.6.12-ci.2

4 years ago

1.6.13

4 years ago

1.6.12

4 years ago

1.6.13-ci.1

4 years ago

2.0.0-next.3

4 years ago

1.6.11

4 years ago

1.6.10

4 years ago

1.6.9

4 years ago

1.6.8

4 years ago

1.6.8-ci.4

4 years ago

1.6.7

4 years ago

1.6.7-ci.4

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

2.0.0-next.1

4 years ago

1.6.4

4 years ago

2.0.0-next.0

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.9

4 years ago

1.5.9-ci.5

4 years ago

1.5.8-ci.13

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.8-alpha.0

4 years ago

1.5.7-alpha.0

4 years ago

1.5.6

4 years ago

1.5.6-alpha.0

4 years ago

1.5.6-ci.0

4 years ago

1.5.5

4 years ago

1.5.4

4 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.18

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.8

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0-rc.4

5 years ago

1.0.0-rc.3

5 years ago

1.0.0-rc.2

5 years ago

1.0.0-rc.0

5 years ago

1.0.0-alpha.13

5 years ago

1.0.0-alpha.11

5 years ago

1.0.0-alpha.10

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

0.20.3

5 years ago

1.0.0-alpha.0

5 years ago

0.18.2

5 years ago

0.18.0

5 years ago

0.17.5

5 years ago

0.17.4

5 years ago

0.17.3

5 years ago

0.17.2

5 years ago

0.17.1

5 years ago

0.17.0

5 years ago