micromark extension to support MDX JS import/exports
Installations
npm install micromark-extension-mdxjs-esm
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.8.1
NPM Version
10.1.0
Score
98.5
Supply Chain
99.5
Quality
75.8
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
161,426,322
Last Day
356,417
Last Week
1,917,143
Last Month
8,215,376
Last Year
80,959,738
GitHub Statistics
MIT License
14 Stars
77 Commits
7 Watchers
1 Branches
11 Contributors
Updated on Oct 27, 2024
Sponsor this package
Package Meta Information
Latest Version
3.0.0
Package Id
micromark-extension-mdxjs-esm@3.0.0
Unpacked Size
33.67 kB
Size
8.38 kB
File Count
11
NPM Version
10.1.0
Node Version
20.8.1
Published on
Oct 19, 2023
Total Downloads
Cumulative downloads
Total Downloads
161,426,322
Last Day
-4.8%
356,417
Compared to previous day
Last Week
-3.3%
1,917,143
Compared to previous week
Last Month
51%
8,215,376
Compared to previous month
Last Year
72.7%
80,959,738
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
9
micromark-extension-mdxjs-esm
micromark extension to support MDX ESM (import x from 'y'
).
Contents
- What is this?
- When to use this
- Install
- Use
- API
- Authoring
- Syntax
- Errors
- Tokens
- Types
- Compatibility
- Security
- Related
- Contribute
- License
What is this?
This package contains an extension that adds support for the ESM syntax enabled
by MDX to micromark
.
These extensions are used inside MDX.
It matches how imports and exports work in JavaScript through acorn.
This package is aware of JavaScript syntax.
When to use this
This project is useful when you want to support ESM in markdown.
You can use this extension when you are working with micromark
.
To support all MDX features, use
micromark-extension-mdxjs
instead.
When you need a syntax tree, combine this package with
mdast-util-mdxjs-esm
.
All these packages are used in remark-mdx
, which focusses on
making it easier to transform content by abstracting these internals away.
When you are using mdx-js/mdx
, all of this is already included.
Install
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install micromark-extension-mdxjs-esm
In Deno with esm.sh
:
1import {mdxjsEsm} from 'https://esm.sh/micromark-extension-mdxjs-esm@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {mdxjsEsm} from 'https://esm.sh/micromark-extension-mdxjs-esm@2?bundle' 3</script>
Use
1import {Parser} from 'acorn' 2import acornJsx from 'acorn-jsx' 3import {micromark} from 'micromark' 4import {mdxjsEsm} from 'micromark-extension-mdxjs-esm' 5 6const acorn = Parser.extend(acornJsx()) 7 8const output = micromark('import a from "b"\n\n# c', { 9 extensions: [mdxjsEsm({acorn})] 10}) 11 12console.log(output)
Yields:
1<h1>c</h1>
…which is useless: go to a syntax tree with
mdast-util-from-markdown
and
mdast-util-mdxjs-esm
instead.
API
This package exports the identifier mdxjsEsm
.
There is no default export.
The export map supports the development
condition.
Run node --conditions development module.js
to get instrumented dev code.
Without this condition, production code is loaded.
mdxjsEsm(options)
Create an extension for micromark
to enable MDX ESM syntax.
Parameters
options
(Options
, required) — configuration
Returns
Extension for micromark
that can be passed in extensions
to enable MDX
ESM syntax (Extension
).
Options
Configuration (TypeScript type).
Fields
acorn
(Acorn
, required) — acorn parser to useacornOptions
(AcornOptions
, default:{ecmaVersion: 2024, locations: true, sourceType: 'module'}
) — configuration for acorn; all fields exceptlocations
can be setaddResult
(boolean
, default:false
) — whether to addestree
fields to tokens with results from acorn
Authoring
When authoring markdown with ESM, make sure to follow export and import statements with blank lines before more markdown.
All valid imports and exports are supported, depending on what the given acorn instance and configuration supports.
When the lowercase strings export
or import
are found, followed by a space,
we expect JavaScript.
Otherwise, like normal in markdown, we exit and it’ll end up as a paragraph.
We continue parsing until we find a blank line.
At that point, we parse with acorn: it if parses, we found our block.
Otherwise, if parsing failed at the last character, we assume it’s a blank line
in code: we continue on until the next blank line and try again.
Otherwise, the acorn error is thrown.
Some examples of valid export and import statements:
1import a from 'b' 2import * as a from 'b' 3import {a} from 'b' 4import {a as b} from 'c' 5import a, {b as c} from 'd' 6import a, * as b from 'c' 7import 'a' 8 9export var a = '' 10export const a = '' 11export let a = '' 12export var a, b 13export var a = 'a', b = 'b' 14export function a() {} 15export class a {} 16export var {a} = {} 17export var {a: b} = {} 18export var [a] = [] 19export default a = 1 20export default function a() {} 21export default class a {} 22export * from 'a' 23export * as a from 'b' 24export {a} from 'b' 25export {a as b} from 'c' 26export {default} from 'b' 27export {default as a, b} from 'c' 28 29{/* Blank lines are supported in expressions: */} 30 31export function a() { 32 33 return 'b' 34 35}
1{/* A blank line must be used after import/exports: this is incorrect! */} 2 3import a from 'b' 4## Hello, world!
Syntax
ESM forms with the following BNF:
1; Restriction: the entire construct must be valid JavaScript. 2mdx_esm ::= word ' ' *line *(eol *line) 3 4word ::= 'e' 'x' 'p' 'o' 'r' 't' | 'i' 'm' 'p' 'o' 'r' 't'
This construct must be followed by a blank line or eof (end of file).
Errors
Could not parse import/exports with acorn
This error occurs if acorn crashes (source: micromark-extension-mdxjs-esm
,
rule id: acorn
).
For example:
1import 1/1
Unexpected $type
in code: only import/exports are supported
This error occurs when a non-ESM construct is found (source:
micromark-extension-mdxjs-esm
, rule id: non-esm
).
For example:
1export var a = 1 2var b
Tokens
An mdxjsEsm
token is used to reflect the block of import/exports in markdown.
It includes:
lineEnding
for the\r
,\n
, and\r\n
lineEndingBlank
for the same characters but when after potential whitespace and another line endingwhitespace
for markdown spaces and tabs in blank linesmdxjsEsmData
for any character in a line ofmdxjsEsm
Types
This package is fully typed with TypeScript.
It exports the additional type Options
.
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,
micromark-extension-mdxjs-esm@^2
, compatible with Node.js 16.
This package works with micromark
version 3
and later.
Security
This package is safe.
Related
micromark-extension-mdxjs
— support all MDX syntaxmdast-util-mdxjs-esm
— support MDX ESM in mdastremark-mdx
— support all MDX syntax in remark
Contribute
See 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.
License

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/micromark/.github/security.md:1
- Info: Found linked content: github.com/micromark/.github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/micromark/.github/security.md:1
- Info: Found text in security policy: github.com/micromark/.github/security.md:1
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-mdxjs-esm/bb.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-mdxjs-esm/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-mdxjs-esm/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-mdxjs-esm/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:15
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/bb.yml:1
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
4.1
/10
Last Scanned on 2025-02-17
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More