Gathering detailed insights and metrics for micromark-extension-mdxjs-esm
Gathering detailed insights and metrics for micromark-extension-mdxjs-esm
micromark extension to support MDX JS import/exports
npm install micromark-extension-mdxjs-esm
Typescript
Module System
Node Version
NPM Version
98.5
Supply Chain
99.5
Quality
75.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
161,426,322
Last Day
356,417
Last Week
1,917,143
Last Month
8,215,376
Last Year
80,959,738
MIT License
14 Stars
77 Commits
7 Watchers
1 Branches
11 Contributors
Updated on Oct 27, 2024
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
Cumulative downloads
Total Downloads
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
9
micromark extension to support MDX ESM (import x from 'y'
).
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.
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.
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>
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.
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.
options
(Options
, required)
— configurationExtension for micromark
that can be passed in extensions
to enable MDX
ESM syntax (Extension
).
Options
Configuration (TypeScript type).
acorn
(Acorn
, required)
— acorn parser to useacornOptions
(AcornOptions
, default:
{ecmaVersion: 2024, locations: true, sourceType: 'module'}
)
— configuration for acorn; all fields except locations
can be setaddResult
(boolean
, default: false
)
— whether to add estree
fields to tokens with results from acornWhen 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!
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).
This error occurs if acorn crashes (source: micromark-extension-mdxjs-esm
,
rule id: acorn
).
For example:
1import 1/1
$type
in code: only import/exports are supportedThis 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
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 of mdxjsEsm
This package is fully typed with TypeScript.
It exports the additional type Options
.
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.
This package is safe.
micromark-extension-mdxjs
— support all MDX syntaxmdast-util-mdxjs-esm
— support MDX ESM in mdastremark-mdx
— support all MDX syntax in remarkSee 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.
MIT © Titus Wormer
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
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