Gathering detailed insights and metrics for micromark-extension-mdx-expression
Gathering detailed insights and metrics for micromark-extension-mdx-expression
micromark extension to support MDX or MDX JS expressions
npm install micromark-extension-mdx-expression
Typescript
Module System
Node Version
NPM Version
99
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
micromark-factory-mdx-expression@2.0.2
Updated on Sep 02, 2024
micromark-extension-mdx-expression@3.0.0
Updated on Oct 19, 2023
micromark-util-events-to-acorn@2.0.2
Updated on Oct 19, 2023
micromark-factory-mdx-expression@2.0.1
Updated on Jul 07, 2023
micromark-util-events-to-acorn@2.0.1
Updated on Jul 07, 2023
2.0.0
Updated on Jun 22, 2023
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
163,427,584
Last Day
367,924
Last Week
1,918,429
Last Month
8,318,374
Last Year
81,348,731
MIT License
11 Stars
157 Commits
2 Forks
7 Watchers
1 Branches
11 Contributors
Updated on Jan 29, 2025
Minified
Minified + Gzipped
Latest Version
3.0.0
Package Id
micromark-extension-mdx-expression@3.0.0
Unpacked Size
33.07 kB
Size
7.63 kB
File Count
10
NPM Version
10.1.0
Node Version
20.8.1
Published on
Oct 19, 2023
Cumulative downloads
Total Downloads
Last Day
-0.4%
367,924
Compared to previous day
Last Week
-4.1%
1,918,429
Compared to previous week
Last Month
47.3%
8,318,374
Compared to previous month
Last Year
71%
81,348,731
Compared to previous year
micromark extension to support MDX expressions ({Math.PI}
).
{
$type
in code: expected an object spread ({...spread}
)This package contains an extension that adds support for the expression syntax
enabled by MDX to micromark
.
These extensions are used inside MDX.
This package can be made aware or unaware of JavaScript syntax. When unaware, expressions could include Rust or variables or whatnot.
This project is useful when you want to support expressions 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-mdx-expression
.
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-mdx-expression
In Deno with esm.sh
:
1import {mdxExpression} from 'https://esm.sh/micromark-extension-mdx-expression@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {mdxExpression} from 'https://esm.sh/micromark-extension-mdx-expression@2?bundle' 3</script>
1import {Parser} from 'acorn' 2import acornJsx from 'acorn-jsx' 3import {micromark} from 'micromark' 4import {mdxExpression} from 'micromark-extension-mdx-expression' 5 6// Unaware of JavaScript (“agnostic”) (balanced braces): 7const output = micromark('a {1 + 1} b', {extensions: [mdxExpression()]}) 8 9console.log(output) 10 11// Aware of JavaScript: 12micromark('a {!} b', {extensions: [mdxExpression({acorn: Parser.extend(acornJsx())})]})
Yields:
1<p>a b</p>
1[1:5: Could not parse expression with acorn] { 2 ancestors: undefined, 3 cause: SyntaxError: Unexpected token 4 at pp$4.raise (file:///Users/tilde/Projects/oss/micromark-extension-mdx-expression/node_modules/acorn/dist/acorn.mjs:3547:13) 5 at pp$9.unexpected (file:///Users/tilde/Projects/oss/micromark-extension-mdx-expression/node_modules/acorn/dist/acorn.mjs:758:8) 6 … 7 pos: 4, 8 loc: { line: 1, column: 4 }, 9 raisedAt: 1 10 }, 11 column: 5, 12 fatal: undefined, 13 line: 1, 14 place: { line: 1, column: 5, offset: 4 }, 15 reason: 'Could not parse expression with acorn', 16 ruleId: 'acorn', 17 source: 'micromark-extension-mdx-expression', 18 url: 'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#could-not-parse-expression-with-acorn' 19}
…which is useless: go to a syntax tree with
mdast-util-from-markdown
and
mdast-util-mdx-expression
instead.
This package exports the identifier mdxExpression
.
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.
mdxExpression(options?)
Create an extension for micromark
to enable MDX expression syntax.
options
(Options
, optional)
— configurationExtension for micromark
that can be passed in extensions
to enable MDX
expression syntax (Extension
).
Configuration (TypeScript type).
acorn
(Acorn
, optional)
— 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 JavaScript, keep in mind that MDX is a whitespace sensitive and line-based language, while JavaScript is insensitive to whitespace. This affects how markdown and JavaScript interleave with eachother in MDX. For more info on how it works, see § Interleaving on the MDX site.
This extension supports MDX both aware and unaware to JavaScript (respectively gnostic and agnostic). Depending on whether acorn is passed, either valid JavaScript must be used in expressions, or arbitrary text (such as Rust code or so) can be used.
There are two types of expressions: in text (inline, span) or in flow (block).
They start with {
.
Depending on whether acorn
is passed, expressions are either parsed in several
tries until whole JavaScript is found (as in, nested curly braces depend on JS
expression nesting), or they are counted and must be balanced.
Expressions end with }
.
For flow (block) expressions, optionally markdown spaces (
or \t
) can occur
after the closing brace, and finally a markdown line ending (\r
, \n
) or the
end of the file must follow.
While markdown typically knows no errors, for MDX it is decided to instead throw on invalid syntax.
1Here is an expression in a heading: 2 3## Hello, {1 + 1}! 4 5In agnostic mode, balanced braces can occur: {a + {b} + c}. 6 7In gnostic mode, the value of the expression must be JavaScript, so 8this would fail: {!}. 9But, in gnostic mode, braces can be in comments, strings, or in other 10places: {1 /* { */ + 2}. 11 12The previous examples were text (inline, span) expressions, they can 13also be flow (block): 14 15{ 16 1 + 1 17} 18 19This is incorrect, because there are further characters: 20 21{ 22 1 + 1 23}!
1Blank lines cannot occur in text, because markdown has already split them in 2separate constructs, so this is incorrect: {1 + 3 41}
1In flow, you can have blank lines: 2 3{ 4 1 + 5 6 2 7}
{
This error occurs if a {
was seen without a }
(source:
micromark-extension-mdx-expression
, rule id: unexpected-eof
).
For example:
1a { b
This error occurs if a {
was seen in a container which then has lazy content
(source: micromark-extension-mdx-expression
, rule id: unexpected-lazy
).
For example:
1> {a 2b}
$type
in code: expected an object spread ({...spread}
)This error occurs if a spread was expected but something else was found
(source: micromark-extension-mdx-expression
, rule id: non-spread
).
For example:
1<a {b=c}={} d>
This error occurs if a spread was expected but more was found after it
(source: micromark-extension-mdx-expression
, rule id: spread-extra
).
For example:
1<a {...b,c} d>
This error occurs if acorn crashes or when there is more content after a JS
expression (source: micromark-extension-mdx-expression
, rule id: acorn
).
For example:
1a {"b" "c"} d
1a {var b = "c"} d
Two tokens are used, mdxFlowExpression
and mdxTextExpression
, to reflect
flow and text expressions.
They include:
lineEnding
for the markdown line endings \r
, \n
, and \r\n
mdxFlowExpressionMarker
and mdxTextExpressionMarker
for the braceswhitespace
for markdown spaces and tabs in blank linesmdxFlowExpressionChunk
and mdxTextExpressionChunk
for chunks of
expression contentThis 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-mdx-expression@^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-mdx-expression
— support MDX expressions 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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
9 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 0/30 approved changesets -- 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 SAST tool detected
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