Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
micromark-extension-mdxjs-esm
Advanced tools
The micromark-extension-mdxjs-esm package is an extension for the micromark Markdown parser that adds support for parsing MDX.js (Markdown for the component era). It allows users to use JSX within their Markdown documents, enabling the embedding of React components and other JSX elements.
Parsing MDX syntax
This feature allows the parsing of MDX syntax within Markdown content. The code sample demonstrates how to use the micromark parser with the mdxjs extension to parse a string containing an MDX component.
import {micromark} from 'micromark';
import {mdxjs} from 'micromark-extension-mdxjs-esm';
const output = micromark('<MyComponent />', {
extensions: [mdxjs()]
});
Support for JSX
This feature enables the use of JSX within Markdown documents. The code sample shows how to parse a Markdown string that includes a JSX component with a prop.
import {micromark} from 'micromark';
import {mdxjs} from 'micromark-extension-mdxjs-esm';
const output = micromark('# Hello, world!\n\n<MyComponent prop1={value} />', {
extensions: [mdxjs()]
});
remark-mdx is a plugin for the remark Markdown processor that adds support for MDX. It is similar to micromark-extension-mdxjs-esm in that it allows for MDX syntax in Markdown files, but it is built on top of the remark ecosystem.
unified is an interface for parsing, transforming, and serializing content through syntax trees and is often used with remark and rehype plugins. While not specific to MDX, it can be used in conjunction with other plugins to achieve similar functionality to micromark-extension-mdxjs-esm.
micromark extension to support MDX.js ESM import/exports.
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.
You should probably use this with mdast-util-mdxjs-esm
(mdast).
Or use micromark-extension-mdxjs
and
mdast-util-mdx
instead, which includes both, to support all
of MDX.js.
Or, use those through remark-mdx
(remark).
npm:
npm install micromark-extension-mdxjs-esm
See mdast-util-mdxjs-esm
for an example.
syntax(options)
Support ESM imports and exports of MDX.
The export of syntax
is a function that can be called with options and returns
an extension for the micromark parser (to tokenize import/exports; can be passed
in extensions
).
options
options.acorn
Acorn parser to use (Acorn
, required).
options.acornOptions
Options to pass to acorn (Object
, default: {ecmaVersion: 2020, locations: true, sourceType: 'module'}
).
All fields except for locations
can be set.
options.addResult
Whether to add an estree
field to mdxjsEsm
tokens with results from acorn
(boolean
, default: false
).
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 unicode
whitespace (\s
), 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 line ending followed by 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.
import a from "b"
import * as a from "b"
import {a} from "b"
import {a as b} from "c"
import a, {b as c} from "d"
import a, * as b from "c"
import "a"
export var a = ""
export const a = ""
export let a = ""
export var a, b
export var a = "a", b = "b"
export function a() {}
export class a {}
export var {a} = {}
export var {a: b} = {}
export var [a] = []
export default a = 1
export default function a() {}
export default class a {}
export * from "a"
export * as a from "b"
export {a} from "b"
export {a as b} from "c"
export {default} from "b"
export {default as a, b} from "c"
{/* Blank lines are supported in expressions: */}
export function a() {
return "b"
}
{/* A blank line must be used after import/exports: this is incorrect! */}
import a from "b"
## Hello, world!
This error occurs if acorn crashes (source: micromark-extension-mdxjs-esm
,
rule id: acorn
).
For example:
import 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:
export var a = 1
var 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
micromark/micromark
— the smallest commonmark-compliant markdown parser that existsmicromark/micromark-extension-mdx
— support MDXmicromark/micromark-extension-mdxjs
— support MDX.jsmicromark/micromark-extension-mdx-expression
— support MDX (or MDX.js) expressionsmicromark/micromark-extension-mdx-jsx
— support MDX (or MDX.js) JSXmicromark/micromark-extension-mdx-md
— support misc MDX changessyntax-tree/mdast-util-mdx
— support MDX (or MDX.js) in mdastSee 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.
FAQs
micromark extension to support MDX JS import/exports
The npm package micromark-extension-mdxjs-esm receives a total of 833,644 weekly downloads. As such, micromark-extension-mdxjs-esm popularity was classified as popular.
We found that micromark-extension-mdxjs-esm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.