A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/micromark/micromark-extension-mdx-jsx below:

micromark/micromark-extension-mdx-jsx: micromark extension to support MDX or MDX.js JSX

micromark-extension-mdx-jsx

micromark extension to support MDX JSX (<Component />).

This package contains an extension that adds support for the JSX syntax enabled by MDX to micromark. These extensions are used inside MDX. It mostly matches how JSX works in most places that support it (TypeScript, Babel, esbuild, SWC, etc).

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 JSX 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-jsx.

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:

npm install micromark-extension-mdx-jsx

In Deno with esm.sh:

import {mdxJsx} from 'https://esm.sh/micromark-extension-mdx-jsx@2'

In browsers with esm.sh:

<script type="module">
  import {mdxJsx} from 'https://esm.sh/micromark-extension-mdx-jsx@2?bundle'
</script>
import {micromark} from 'micromark'
import {mdxJsx} from 'micromark-extension-mdx-jsx'

const output = micromark('a <b c d="e" /> f', {extensions: [mdxJsx()]})

console.log(output)

Yields:

…which is useless: go to a syntax tree with mdast-util-from-markdown and mdast-util-mdx-jsx instead.

This package exports the identifier mdxJsx. 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.

Create an extension for micromark to enable MDX JSX syntax.

Extension for micromark that can be passed in extensions to enable MDX JSX syntax (Extension).

Configuration (TypeScript type).

When authoring markdown with JSX, keep in mind that MDX is a whitespace sensitive and line-based language, while JavaScript is insensitive to whitespace. This affects how markdown and JSX interleave with eachother in MDX. For more info on how it works, see § Interleaving on the MDX site.

JavaScript comments in JSX are not supported.

Incorrect:

<hi/*comment!*//>
<hello// comment!
/>

Correct:

A PR that adds support for them would be accepted.

Element or fragment attribute values

JSX elements or JSX fragments as attribute values are not supported. The reason for this change is that it would be confusing whether markdown would work.

Incorrect:

<welcome name=<>Venus</> />
<welcome name=<span>Pluto</span> />

Correct:

<welcome name='Mars' />
<welcome name={<span>Jupiter</span>} />
Greater than (>) and right curly brace (})

JSX does not allow U+003E GREATER THAN (>) or U+007D RIGHT CURLY BRACE (}) literally in text, they need to be encoded as character references (or expressions). There is no good reason for this (some JSX parsers agree with us and don’t crash either). Therefore, in MDX, U+003E GREATER THAN (>) and U+007D RIGHT CURLY BRACE (}) are fine literally and don’t need to be encoded.

JSX forms with the following BNF:

As the flow construct occurs in flow, like all flow constructs, it must be followed by an eol (line ending) or eof (end of file).

The grammar for JSX in markdown is much stricter than that of HTML in markdown. The primary benefit of this is that tags are parsed into tokens, and thus can be processed. Another, arguable, benefit of this is that it comes with syntax errors: if an author types something that is nonsensical, an error is thrown with information about where it happened, what occurred, and what was expected instead.

This extension supports expressions 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.

More on this can be found in § Syntax of micromark-extension-mdx-expression.

In aware (gnostic) mode, expressions are parsed with micromark-extension-mdx-expression, which throws some more errors.

Unexpected end of file $at, expected $expect

This error occurs for many different reasons if something was opened but not closed (source: micromark-extension-mdx-jsx, rule id: unexpected-eof).

Some examples are:

<
</
<a
<a:
<a.
<a b
<a b:
<a b=
<a b="
<a b='
<a b={
<a/
Unexpected character $at, expected $expect

This error occurs for many different reasons if an unexpected character is seen (source: micromark-extension-mdx-jsx, rule id: unexpected-character).

Some examples are:

<.>
</.>
<a?>
<a:+>
<a./>
<a b!>
<a b:1>
<a b=>
<a/->
Unexpected lazy line in container, expected line to be…

This error occurs if a < was seen in a container which then has lazy content (source: micromark-extension-mdx-jsx, rule id: unexpected-lazy). For example:

Many tokens are used:

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-mdx-jsx@2, compatible with Node.js 16.

This package works with micromark version 3 and later.

This package is safe.

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.

MIT © Titus Wormer


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4