🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

273
node_modules/mdast-util-mdx-jsx/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,273 @@
import type {Node as MdastNode} from 'unist'
import type {
Parent as MdastParent,
Literal as MdastLiteral,
BlockContent,
DefinitionContent,
PhrasingContent
} from 'mdast'
import type {ElementContent, Parent as HastParent} from 'hast'
import type {Program} from 'estree-jsx'
import type {Tag} from './lib/index.js'
// Expose JavaScript API.
export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js'
// Expose options.
export type {ToMarkdownOptions} from './lib/index.js'
// Expose node types.
/**
* MDX JSX attribute value set to an expression.
*
* ```markdown
* > | <a b={c} />
* ^^^
* ```
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxAttributeValueExpression extends MdastLiteral {
/**
* Node type.
*/
type: 'mdxJsxAttributeValueExpression'
data?: {
/**
* Program node from estree.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
estree?: Program | null | undefined
} & MdastLiteral['data']
}
/**
* MDX JSX attribute as an expression.
*
* ```markdown
* > | <a {...b} />
* ^^^^^^
* ```
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxExpressionAttribute extends MdastLiteral {
/**
* Node type.
*/
type: 'mdxJsxExpressionAttribute'
data?: {
/**
* Program node from estree.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
estree?: Program | null | undefined
} & MdastLiteral['data']
}
/**
* MDX JSX attribute with a key.
*
* ```markdown
* > | <a b="c" />
* ^^^^^
* ```
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxAttribute extends MdastNode {
/**
* Node type.
*/
type: 'mdxJsxAttribute'
/**
* Attribute name.
*/
name: string
/**
* Attribute value.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
value?: MdxJsxAttributeValueExpression | string | null | undefined
}
/**
* MDX JSX element node, occurring in flow (block).
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxFlowElement extends MdastParent {
/**
* Node type.
*/
type: 'mdxJsxFlowElement'
/**
* MDX JSX element name (`null` for fragments).
*/
// eslint-disable-next-line @typescript-eslint/ban-types
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: Array<BlockContent | DefinitionContent>
}
/**
* MDX JSX element node, occurring in text (phrasing).
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxTextElement extends MdastParent {
/**
* Node type.
*/
type: 'mdxJsxTextElement'
/**
* MDX JSX element name (`null` for fragments).
*/
// eslint-disable-next-line @typescript-eslint/ban-types
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: PhrasingContent[]
}
/**
* MDX JSX element node, occurring in flow (block), for hast.
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxFlowElementHast extends HastParent {
/**
* Node type.
*/
type: 'mdxJsxFlowElement'
/**
* MDX JSX element name (`null` for fragments).
*/
// eslint-disable-next-line @typescript-eslint/ban-types
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: ElementContent[]
}
/**
* MDX JSX element node, occurring in text (phrasing), for hast.
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxJsxTextElementHast extends HastParent {
/**
* Node type.
*/
type: 'mdxJsxTextElement'
/**
* MDX JSX element name (`null` for fragments).
*/
// eslint-disable-next-line @typescript-eslint/ban-types
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: ElementContent[]
}
// Add nodes to mdast content.
declare module 'mdast' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface StaticPhrasingContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElement
}
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface BlockContentMap {
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElement
}
}
// Add nodes to hast content.
declare module 'hast' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface RootContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElementHast
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElementHast
}
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface ElementContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElementHast
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElementHast
}
}
// Add custom data tracked to turn markdown into a tree.
declare module 'mdast-util-from-markdown' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface CompileData {
/**
* Current MDX JSX tag.
*/
mdxJsxTag?: Tag | undefined
/**
* Current stack of open MDX JSX tags.
*/
mdxJsxTagStack?: Tag[] | undefined
}
}
// Add custom data tracked to turn a syntax tree into markdown.
declare module 'mdast-util-to-markdown' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface ConstructNameMap {
/**
* Whole JSX element, in flow.
*
* ```markdown
* > | <a />
* ^^^^^
* ```
*/
mdxJsxFlowElement: 'mdxJsxFlowElement'
/**
* Whole JSX element, in text.
*
* ```markdown
* > | a <b />.
* ^^^^^
* ```
*/
mdxJsxTextElement: 'mdxJsxTextElement'
}
}

2
node_modules/mdast-util-mdx-jsx/index.js generated vendored Normal file
View file

@ -0,0 +1,2 @@
// Note: types exposed from `index.d.ts`.
export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js'

11
node_modules/mdast-util-mdx-jsx/lib/complex-types.d.ts generated vendored Normal file
View file

@ -0,0 +1,11 @@
// To do: next major: remove this file.
export type {
MdxJsxAttributeValueExpression,
MdxJsxAttribute,
MdxJsxExpressionAttribute,
MdxJsxFlowElement,
MdxJsxTextElement,
ToMarkdownOptions
} from '../index.js'
/// <reference types="../index.js" />

102
node_modules/mdast-util-mdx-jsx/lib/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,102 @@
/**
* Create an extension for `mdast-util-from-markdown` to enable MDX JSX.
*
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-from-markdown` to enable MDX JSX.
*
* When using the syntax extension with `addResult`, nodes will have a
* `data.estree` field set to an ESTree `Program` node.
*/
export function mdxJsxFromMarkdown(): FromMarkdownExtension
/**
* Create an extension for `mdast-util-to-markdown` to enable MDX JSX.
*
* This extension configures `mdast-util-to-markdown` with
* `options.fences: true` and `options.resourceLink: true` too, do not
* overwrite them!
*
* @param {ToMarkdownOptions | null | undefined} [options]
* Configuration.
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable MDX JSX.
*/
export function mdxJsxToMarkdown(
options?: ToMarkdownOptions | null | undefined
): ToMarkdownExtension
export type Program = import('estree-jsx').Program
export type CompileContext = import('mdast-util-from-markdown').CompileContext
export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension
export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle
export type Token = import('mdast-util-from-markdown').Token
export type OnEnterError = import('mdast-util-from-markdown').OnEnterError
export type OnExitError = import('mdast-util-from-markdown').OnExitError
export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle
export type ToMarkdownExtension = import('mdast-util-to-markdown').Options
export type State = import('mdast-util-to-markdown').State
export type Tracker = import('mdast-util-to-markdown').Tracker
export type MdxJsxAttributeValueExpression =
import('../index.js').MdxJsxAttributeValueExpression
export type MdxJsxAttribute = import('../index.js').MdxJsxAttribute
export type MdxJsxExpressionAttribute =
import('../index.js').MdxJsxExpressionAttribute
export type MdxJsxFlowElement = import('../index.js').MdxJsxFlowElement
export type MdxJsxTextElement = import('../index.js').MdxJsxTextElement
/**
* Single tag.
*/
export type Tag = {
/**
* Name of tag, or `undefined` for fragment.
*
* > 👉 **Note**: `null` is used in the AST for fragments, as it serializes in
* > JSON.
*/
name: string | undefined
/**
* Attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Whether the tag is closing (`</x>`).
*/
close: boolean
/**
* Whether the tag is self-closing (`<x/>`).
*/
selfClosing: boolean
/**
* Start point.
*/
start: Token['start']
/**
* End point.
*/
end: Token['start']
}
/**
* Configuration.
*/
export type ToMarkdownOptions = {
/**
* Preferred quote to use around attribute values.
*/
quote?: '"' | "'" | null | undefined
/**
* Use the other quote if that results in less bytes.
*/
quoteSmart?: boolean | null | undefined
/**
* Do not use an extra space when closing self-closing elements: `<img/>`
* instead of `<img />`.
*/
tightSelfClosing?: boolean | null | undefined
/**
* Try and wrap syntax at this width.
*
* When set to a finite number (say, `80`), the formatter will print
* attributes on separate lines when a tag doesnt fit on one line.
* The normal behavior is to print attributes with spaces between them
* instead of line endings.
*/
printWidth?: number | null | undefined
}

756
node_modules/mdast-util-mdx-jsx/lib/index.js generated vendored Normal file
View file

@ -0,0 +1,756 @@
/**
* @typedef {import('estree-jsx').Program} Program
*
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
* @typedef {import('mdast-util-from-markdown').Token} Token
* @typedef {import('mdast-util-from-markdown').OnEnterError} OnEnterError
* @typedef {import('mdast-util-from-markdown').OnExitError} OnExitError
*
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
* @typedef {import('mdast-util-to-markdown').State} State
* @typedef {import('mdast-util-to-markdown').Tracker} Tracker
*
* @typedef {import('../index.js').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
* @typedef {import('../index.js').MdxJsxAttribute} MdxJsxAttribute
* @typedef {import('../index.js').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute
* @typedef {import('../index.js').MdxJsxFlowElement} MdxJsxFlowElement
* @typedef {import('../index.js').MdxJsxTextElement} MdxJsxTextElement
*/
/**
* @typedef Tag
* Single tag.
* @property {string | undefined} name
* Name of tag, or `undefined` for fragment.
*
* > 👉 **Note**: `null` is used in the AST for fragments, as it serializes in
* > JSON.
* @property {Array<MdxJsxAttribute | MdxJsxExpressionAttribute>} attributes
* Attributes.
* @property {boolean} close
* Whether the tag is closing (`</x>`).
* @property {boolean} selfClosing
* Whether the tag is self-closing (`<x/>`).
* @property {Token['start']} start
* Start point.
* @property {Token['start']} end
* End point.
*
* @typedef ToMarkdownOptions
* Configuration.
* @property {'"' | "'" | null | undefined} [quote='"']
* Preferred quote to use around attribute values.
* @property {boolean | null | undefined} [quoteSmart=false]
* Use the other quote if that results in less bytes.
* @property {boolean | null | undefined} [tightSelfClosing=false]
* Do not use an extra space when closing self-closing elements: `<img/>`
* instead of `<img />`.
* @property {number | null | undefined} [printWidth=Infinity]
* Try and wrap syntax at this width.
*
* When set to a finite number (say, `80`), the formatter will print
* attributes on separate lines when a tag doesnt fit on one line.
* The normal behavior is to print attributes with spaces between them
* instead of line endings.
*/
import {ccount} from 'ccount'
import {parseEntities} from 'parse-entities'
import {stringifyPosition} from 'unist-util-stringify-position'
import {VFileMessage} from 'vfile-message'
import {stringifyEntitiesLight} from 'stringify-entities'
import {containerPhrasing} from 'mdast-util-to-markdown/lib/util/container-phrasing.js'
import {indentLines} from 'mdast-util-to-markdown/lib/util/indent-lines.js'
import {track} from 'mdast-util-to-markdown/lib/util/track.js'
// To do: next major: use `state`, use utilities from state, rename `safeOptions` to `info`.
const indent = ' '
/**
* Create an extension for `mdast-util-from-markdown` to enable MDX JSX.
*
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-from-markdown` to enable MDX JSX.
*
* When using the syntax extension with `addResult`, nodes will have a
* `data.estree` field set to an ESTree `Program` node.
*/
export function mdxJsxFromMarkdown() {
return {
canContainEols: ['mdxJsxTextElement'],
enter: {
mdxJsxFlowTag: enterMdxJsxTag,
mdxJsxFlowTagClosingMarker: enterMdxJsxTagClosingMarker,
mdxJsxFlowTagAttribute: enterMdxJsxTagAttribute,
mdxJsxFlowTagExpressionAttribute: enterMdxJsxTagExpressionAttribute,
mdxJsxFlowTagAttributeValueLiteral: buffer,
mdxJsxFlowTagAttributeValueExpression: buffer,
mdxJsxFlowTagSelfClosingMarker: enterMdxJsxTagSelfClosingMarker,
mdxJsxTextTag: enterMdxJsxTag,
mdxJsxTextTagClosingMarker: enterMdxJsxTagClosingMarker,
mdxJsxTextTagAttribute: enterMdxJsxTagAttribute,
mdxJsxTextTagExpressionAttribute: enterMdxJsxTagExpressionAttribute,
mdxJsxTextTagAttributeValueLiteral: buffer,
mdxJsxTextTagAttributeValueExpression: buffer,
mdxJsxTextTagSelfClosingMarker: enterMdxJsxTagSelfClosingMarker
},
exit: {
mdxJsxFlowTagClosingMarker: exitMdxJsxTagClosingMarker,
mdxJsxFlowTagNamePrimary: exitMdxJsxTagNamePrimary,
mdxJsxFlowTagNameMember: exitMdxJsxTagNameMember,
mdxJsxFlowTagNameLocal: exitMdxJsxTagNameLocal,
mdxJsxFlowTagExpressionAttribute: exitMdxJsxTagExpressionAttribute,
mdxJsxFlowTagExpressionAttributeValue: data,
mdxJsxFlowTagAttributeNamePrimary: exitMdxJsxTagAttributeNamePrimary,
mdxJsxFlowTagAttributeNameLocal: exitMdxJsxTagAttributeNameLocal,
mdxJsxFlowTagAttributeValueLiteral: exitMdxJsxTagAttributeValueLiteral,
mdxJsxFlowTagAttributeValueLiteralValue: data,
mdxJsxFlowTagAttributeValueExpression:
exitMdxJsxTagAttributeValueExpression,
mdxJsxFlowTagAttributeValueExpressionValue: data,
mdxJsxFlowTagSelfClosingMarker: exitMdxJsxTagSelfClosingMarker,
mdxJsxFlowTag: exitMdxJsxTag,
mdxJsxTextTagClosingMarker: exitMdxJsxTagClosingMarker,
mdxJsxTextTagNamePrimary: exitMdxJsxTagNamePrimary,
mdxJsxTextTagNameMember: exitMdxJsxTagNameMember,
mdxJsxTextTagNameLocal: exitMdxJsxTagNameLocal,
mdxJsxTextTagExpressionAttribute: exitMdxJsxTagExpressionAttribute,
mdxJsxTextTagExpressionAttributeValue: data,
mdxJsxTextTagAttributeNamePrimary: exitMdxJsxTagAttributeNamePrimary,
mdxJsxTextTagAttributeNameLocal: exitMdxJsxTagAttributeNameLocal,
mdxJsxTextTagAttributeValueLiteral: exitMdxJsxTagAttributeValueLiteral,
mdxJsxTextTagAttributeValueLiteralValue: data,
mdxJsxTextTagAttributeValueExpression:
exitMdxJsxTagAttributeValueExpression,
mdxJsxTextTagAttributeValueExpressionValue: data,
mdxJsxTextTagSelfClosingMarker: exitMdxJsxTagSelfClosingMarker,
mdxJsxTextTag: exitMdxJsxTag
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function buffer() {
this.buffer()
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function data(token) {
this.config.enter.data.call(this, token)
this.config.exit.data.call(this, token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTag(token) {
/** @type {Tag} */
const tag = {
name: undefined,
attributes: [],
close: false,
selfClosing: false,
start: token.start,
end: token.end
}
if (!this.getData('mdxJsxTagStack')) this.setData('mdxJsxTagStack', [])
this.setData('mdxJsxTag', tag)
this.buffer()
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagClosingMarker(token) {
const stack = /** @type {Array<Tag>} */ (this.getData('mdxJsxTagStack'))
if (stack.length === 0) {
throw new VFileMessage(
'Unexpected closing slash `/` in tag, expected an open tag first',
{start: token.start, end: token.end},
'mdast-util-mdx-jsx:unexpected-closing-slash'
)
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagAnyAttribute(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
if (tag.close) {
throw new VFileMessage(
'Unexpected attribute in closing tag, expected the end of the tag',
{start: token.start, end: token.end},
'mdast-util-mdx-jsx:unexpected-attribute'
)
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagSelfClosingMarker(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
if (tag.close) {
throw new VFileMessage(
'Unexpected self-closing slash `/` in closing tag, expected the end of the tag',
{start: token.start, end: token.end},
'mdast-util-mdx-jsx:unexpected-self-closing-slash'
)
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagClosingMarker() {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
tag.close = true
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagNamePrimary(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
tag.name = this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagNameMember(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
tag.name += '.' + this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagNameLocal(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
tag.name += ':' + this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagAttribute(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
enterMdxJsxTagAnyAttribute.call(this, token)
tag.attributes.push({type: 'mdxJsxAttribute', name: '', value: null})
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagExpressionAttribute(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
enterMdxJsxTagAnyAttribute.call(this, token)
tag.attributes.push({type: 'mdxJsxExpressionAttribute', value: ''})
this.buffer()
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagExpressionAttribute(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
const tail = /** @type {MdxJsxExpressionAttribute} */ (
tag.attributes[tag.attributes.length - 1]
)
/** @type {Program | undefined} */
// @ts-expect-error: custom.
const estree = token.estree
tail.value = this.resume()
if (estree) {
tail.data = {estree}
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeNamePrimary(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
const node = /** @type {MdxJsxAttribute} */ (
tag.attributes[tag.attributes.length - 1]
)
node.name = this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeNameLocal(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
const node = /** @type {MdxJsxAttribute} */ (
tag.attributes[tag.attributes.length - 1]
)
node.name += ':' + this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeValueLiteral() {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
tag.attributes[tag.attributes.length - 1].value = parseEntities(
this.resume(),
{nonTerminated: false}
)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeValueExpression(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
const tail = /** @type {MdxJsxAttribute} */ (
tag.attributes[tag.attributes.length - 1]
)
/** @type {MdxJsxAttributeValueExpression} */
const node = {type: 'mdxJsxAttributeValueExpression', value: this.resume()}
/** @type {Program | undefined} */
// @ts-expect-error: custom.
const estree = token.estree
if (estree) {
node.data = {estree}
}
tail.value = node
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagSelfClosingMarker() {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
tag.selfClosing = true
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTag(token) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
const stack = /** @type {Array<Tag>} */ (this.getData('mdxJsxTagStack'))
const tail = stack[stack.length - 1]
if (tag.close && tail.name !== tag.name) {
throw new VFileMessage(
'Unexpected closing tag `' +
serializeAbbreviatedTag(tag) +
'`, expected corresponding closing tag for `' +
serializeAbbreviatedTag(tail) +
'` (' +
stringifyPosition(tail) +
')',
{start: token.start, end: token.end},
'mdast-util-mdx-jsx:end-tag-mismatch'
)
}
// End of a tag, so drop the buffer.
this.resume()
if (tag.close) {
stack.pop()
} else {
this.enter(
{
type:
token.type === 'mdxJsxTextTag'
? 'mdxJsxTextElement'
: 'mdxJsxFlowElement',
name: tag.name || null,
attributes: tag.attributes,
children: []
},
token,
onErrorRightIsTag
)
}
if (tag.selfClosing || tag.close) {
this.exit(token, onErrorLeftIsTag)
} else {
stack.push(tag)
}
}
/**
* @this {CompileContext}
* @type {OnEnterError}
*/
function onErrorRightIsTag(closing, open) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
const place = closing ? ' before the end of `' + closing.type + '`' : ''
const position = closing
? {start: closing.start, end: closing.end}
: undefined
throw new VFileMessage(
'Expected a closing tag for `' +
serializeAbbreviatedTag(tag) +
'` (' +
stringifyPosition({start: open.start, end: open.end}) +
')' +
place,
position,
'mdast-util-mdx-jsx:end-tag-mismatch'
)
}
/**
* @this {CompileContext}
* @type {OnExitError}
*/
function onErrorLeftIsTag(a, b) {
const tag = /** @type {Tag} */ (this.getData('mdxJsxTag'))
throw new VFileMessage(
'Expected the closing tag `' +
serializeAbbreviatedTag(tag) +
'` either after the end of `' +
b.type +
'` (' +
stringifyPosition(b.end) +
') or another opening tag after the start of `' +
b.type +
'` (' +
stringifyPosition(b.start) +
')',
{start: a.start, end: a.end},
'mdast-util-mdx-jsx:end-tag-mismatch'
)
}
/**
* Serialize a tag, excluding attributes.
* `self-closing` is not supported, because we dont need it yet.
*
* @param {Tag} tag
* @returns {string}
*/
function serializeAbbreviatedTag(tag) {
return '<' + (tag.close ? '/' : '') + (tag.name || '') + '>'
}
}
/**
* Create an extension for `mdast-util-to-markdown` to enable MDX JSX.
*
* This extension configures `mdast-util-to-markdown` with
* `options.fences: true` and `options.resourceLink: true` too, do not
* overwrite them!
*
* @param {ToMarkdownOptions | null | undefined} [options]
* Configuration.
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable MDX JSX.
*/
export function mdxJsxToMarkdown(options) {
const options_ = options || {}
const quote = options_.quote || '"'
const quoteSmart = options_.quoteSmart || false
const tightSelfClosing = options_.tightSelfClosing || false
const printWidth = options_.printWidth || Number.POSITIVE_INFINITY
const alternative = quote === '"' ? "'" : '"'
if (quote !== '"' && quote !== "'") {
throw new Error(
'Cannot serialize attribute values with `' +
quote +
'` for `options.quote`, expected `"`, or `\'`'
)
}
mdxElement.peek = peekElement
return {
handlers: {
mdxJsxFlowElement: mdxElement,
mdxJsxTextElement: mdxElement
},
unsafe: [
{character: '<', inConstruct: ['phrasing']},
{atBreak: true, character: '<'}
],
// Always generate fenced code (never indented code).
fences: true,
// Always generate links with resources (never autolinks).
resourceLink: true
}
/**
* @type {ToMarkdownHandle}
* @param {MdxJsxFlowElement | MdxJsxTextElement} node
*/
// eslint-disable-next-line complexity
function mdxElement(node, _, context, safeOptions) {
const flow = node.type === 'mdxJsxFlowElement'
const selfClosing = node.name
? !node.children || node.children.length === 0
: false
const depth = inferDepth(context)
const currentIndent = createIndent(depth)
const trackerOneLine = track(safeOptions)
const trackerMultiLine = track(safeOptions)
/** @type {Array<string>} */
const serializedAttributes = []
const prefix = (flow ? currentIndent : '') + '<' + (node.name || '')
const exit = context.enter(node.type)
trackerOneLine.move(prefix)
trackerMultiLine.move(prefix)
// None.
if (node.attributes && node.attributes.length > 0) {
if (!node.name) {
throw new Error('Cannot serialize fragment w/ attributes')
}
let index = -1
while (++index < node.attributes.length) {
const attribute = node.attributes[index]
/** @type {string} */
let result
if (attribute.type === 'mdxJsxExpressionAttribute') {
result = '{' + (attribute.value || '') + '}'
} else {
if (!attribute.name) {
throw new Error('Cannot serialize attribute w/o name')
}
const value = attribute.value
const left = attribute.name
/** @type {string} */
let right = ''
if (value === undefined || value === null) {
// Empty.
} else if (typeof value === 'object') {
right = '{' + (value.value || '') + '}'
} else {
// If the alternative is less common than `quote`, switch.
const appliedQuote =
quoteSmart && ccount(value, quote) > ccount(value, alternative)
? alternative
: quote
right =
appliedQuote +
stringifyEntitiesLight(value, {subset: [appliedQuote]}) +
appliedQuote
}
result = left + (right ? '=' : '') + right
}
serializedAttributes.push(result)
}
}
let attributesOnTheirOwnLine = false
const attributesOnOneLine = serializedAttributes.join(' ')
if (
// Block:
flow &&
// Including a line ending (expressions).
(/\r?\n|\r/.test(attributesOnOneLine) ||
// Current position (including `<tag`).
trackerOneLine.current().now.column +
// -1 because columns, +1 for ` ` before attributes.
// Attributes joined by spaces.
attributesOnOneLine.length +
// ` />`.
(selfClosing ? (tightSelfClosing ? 2 : 3) : 1) >
printWidth)
) {
attributesOnTheirOwnLine = true
}
let tracker = trackerOneLine
let value = prefix
if (attributesOnTheirOwnLine) {
tracker = trackerMultiLine
let index = -1
while (++index < serializedAttributes.length) {
// Only indent first line of of attributes, we cant indent attribute
// values.
serializedAttributes[index] =
currentIndent + indent + serializedAttributes[index]
}
value += tracker.move(
'\n' + serializedAttributes.join('\n') + '\n' + currentIndent
)
} else if (attributesOnOneLine) {
value += tracker.move(' ' + attributesOnOneLine)
}
if (selfClosing) {
value += tracker.move(
(tightSelfClosing || attributesOnTheirOwnLine ? '' : ' ') + '/'
)
}
value += tracker.move('>')
if (node.children && node.children.length > 0) {
if (node.type === 'mdxJsxTextElement') {
value += tracker.move(
containerPhrasing(node, context, {
...tracker.current(),
before: '>',
after: '<'
})
)
} else {
tracker.shift(2)
value += tracker.move('\n')
value += tracker.move(containerFlow(node, context, tracker.current()))
value += tracker.move('\n')
}
}
if (!selfClosing) {
value += tracker.move(
(flow ? currentIndent : '') + '</' + (node.name || '') + '>'
)
}
exit()
return value
}
}
// Modified copy of:
// <https://github.com/syntax-tree/mdast-util-to-markdown/blob/a381cbc/lib/util/container-flow.js>.
//
// To do: add `indent` support to `mdast-util-to-markdown`.
// As indents are only used for JSX, its fine for now, but perhaps better
// there.
/**
* @param {MdxJsxFlowElement} parent
* Parent of flow nodes.
* @param {State} state
* Info passed around about the current state.
* @param {ReturnType<Tracker['current']>} info
* Info on where we are in the document we are generating.
* @returns {string}
* Serialized children, joined by (blank) lines.
*/
function containerFlow(parent, state, info) {
const indexStack = state.indexStack
const children = parent.children
const tracker = state.createTracker(info)
const currentIndent = createIndent(inferDepth(state))
/** @type {Array<string>} */
const results = []
let index = -1
indexStack.push(-1)
while (++index < children.length) {
const child = children[index]
indexStack[indexStack.length - 1] = index
const childInfo = {before: '\n', after: '\n', ...tracker.current()}
const result = state.handle(child, parent, state, childInfo)
const serializedChild =
child.type === 'mdxJsxFlowElement'
? result
: indentLines(result, function (line, _, blank) {
return (blank ? '' : currentIndent) + line
})
results.push(tracker.move(serializedChild))
if (child.type !== 'list') {
state.bulletLastUsed = undefined
}
if (index < children.length - 1) {
results.push(tracker.move('\n\n'))
}
}
indexStack.pop()
return results.join('')
}
/**
*
* @param {State} context
* @returns {number}
*/
function inferDepth(context) {
let depth = 0
for (const x of context.stack) {
if (x === 'mdxJsxFlowElement') {
depth++
}
}
return depth
}
/**
* @param {number} depth
* @returns {string}
*/
function createIndent(depth) {
return indent.repeat(depth)
}
/**
* @type {ToMarkdownHandle}
*/
function peekElement() {
return '<'
}

22
node_modules/mdast-util-mdx-jsx/license generated vendored Normal file
View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

95
node_modules/mdast-util-mdx-jsx/package.json generated vendored Normal file
View file

@ -0,0 +1,95 @@
{
"name": "mdast-util-mdx-jsx",
"version": "2.1.4",
"description": "mdast extension to parse and serialize MDX or MDX.js JSX",
"license": "MIT",
"keywords": [
"unist",
"mdast",
"mdast-util",
"util",
"utility",
"markdown",
"markup",
"mdx",
"mdxjs",
"jsx",
"extension"
],
"repository": "syntax-tree/mdast-util-mdx-jsx",
"bugs": "https://github.com/syntax-tree/mdast-util-mdx-jsx/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree-jsx": "^1.0.0",
"@types/hast": "^2.0.0",
"@types/mdast": "^3.0.0",
"@types/unist": "^2.0.0",
"ccount": "^2.0.0",
"mdast-util-from-markdown": "^1.1.0",
"mdast-util-to-markdown": "^1.3.0",
"parse-entities": "^4.0.0",
"stringify-entities": "^4.0.0",
"unist-util-remove-position": "^4.0.0",
"unist-util-stringify-position": "^3.0.0",
"vfile-message": "^3.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"acorn": "^8.0.0",
"c8": "^7.0.0",
"micromark-extension-mdx-jsx": "^1.0.0",
"micromark-extension-mdx-md": "^1.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.54.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

715
node_modules/mdast-util-mdx-jsx/readme.md generated vendored Normal file
View file

@ -0,0 +1,715 @@
# mdast-util-mdx-jsx
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[mdast][] extensions to parse and serialize [MDX][] JSX (`<a />`).
## Contents
* [What is this?](#what-is-this)
* [When to use this](#when-to-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`mdxJsxFromMarkdown()`](#mdxjsxfrommarkdown)
* [`mdxJsxToMarkdown(options?)`](#mdxjsxtomarkdownoptions)
* [`MdxJsxAttribute`](#mdxjsxattribute)
* [`MdxJsxAttributeValueExpression`](#mdxjsxattributevalueexpression)
* [`MdxJsxExpressionAttribute`](#mdxjsxexpressionattribute)
* [`MdxJsxFlowElement`](#mdxjsxflowelement)
* [`MdxJsxFlowElementHast`](#mdxjsxflowelementhast)
* [`MdxJsxTextElement`](#mdxjsxtextelement)
* [`MdxJsxTextElementHast`](#mdxjsxtextelementhast)
* [`ToMarkdownOptions`](#tomarkdownoptions)
* [HTML](#html)
* [Syntax](#syntax)
* [Syntax tree](#syntax-tree)
* [Nodes](#nodes)
* [Mixin](#mixin)
* [Content model](#content-model)
* [Types](#types)
* [Compatibility](#compatibility)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package contains two extensions that add support for MDX JSX syntax in
markdown to [mdast][].
These extensions plug into
[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing
JSX in markdown into a syntax tree) and
[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing
JSX in syntax trees to markdown).
[JSX][] is an XML-like syntax extension to ECMAScript (JavaScript), which MDX
brings to markdown.
For more info on MDX, see [What is MDX?][what-is-mdx]
## When to use this
You can use these extensions when you are working with
`mdast-util-from-markdown` and `mdast-util-to-markdown` already.
When working with `mdast-util-from-markdown`, you must combine this package
with [`micromark-extension-mdx-jsx`][micromark-extension-mdx-jsx].
When you are working with syntax trees and want all of MDX, use
[`mdast-util-mdx`][mdast-util-mdx] instead.
All these packages are used in [`remark-mdx`][remark-mdx], which
focusses on making it easier to transform content by abstracting these
internals away.
## Install
This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
```sh
npm install mdast-util-mdx-jsx
```
In Deno with [`esm.sh`][esmsh]:
```js
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@2?bundle'
</script>
```
## Use
Say our document `example.mdx` contains:
```mdx
<Box>
- a list
</Box>
<MyComponent {...props} />
<abbr title="Hypertext Markup Language">HTML</abbr> is a lovely language.
```
…and our module `example.js` looks as follows:
```js
import fs from 'node:fs/promises'
import * as acorn from 'acorn'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toMarkdown} from 'mdast-util-to-markdown'
import {mdxJsx} from 'micromark-extension-mdx-jsx'
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'mdast-util-mdx-jsx'
const doc = await fs.readFile('example.mdx')
const tree = fromMarkdown(doc, {
extensions: [mdxJsx({acorn, addResult: true})],
mdastExtensions: [mdxJsxFromMarkdown()]
})
console.log(tree)
const out = toMarkdown(tree, {extensions: [mdxJsxToMarkdown()]})
console.log(out)
```
…now running `node example.js` yields (positional info removed for brevity):
```js
{
type: 'root',
children: [
{
type: 'mdxJsxFlowElement',
name: 'Box',
attributes: [],
children: [
{
type: 'list',
ordered: false,
start: null,
spread: false,
children: [
{
type: 'listItem',
spread: false,
checked: null,
children: [
{type: 'paragraph', children: [{type: 'text', value: 'a list'}]}
]
}
]
}
]
},
{
type: 'mdxJsxFlowElement',
name: 'MyComponent',
attributes: [
{
type: 'mdxJsxExpressionAttribute',
value: '...props',
data: {
estree: {
type: 'Program',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'ObjectExpression',
properties: [
{
type: 'SpreadElement',
argument: {type: 'Identifier', name: 'props'}
}
]
}
}
],
sourceType: 'module'
}
}
}
],
children: []
},
{
type: 'paragraph',
children: [
{
type: 'mdxJsxTextElement',
name: 'abbr',
attributes: [
{
type: 'mdxJsxAttribute',
name: 'title',
value: 'Hypertext Markup Language'
}
],
children: [{type: 'text', value: 'HTML'}]
},
{type: 'text', value: ' is a lovely language.'}
]
}
]
}
```
```markdown
<Box>
* a list
</Box>
<MyComponent {...props} />
<abbr title="Hypertext Markup Language">HTML</abbr> is a lovely language.
```
## API
This package exports the identifiers
[`mdxJsxFromMarkdown`][api-mdx-jsx-from-markdown] and
[`mdxJsxToMarkdown`][api-mdx-jsx-to-markdown].
There is no default export.
### `mdxJsxFromMarkdown()`
Create an extension for
[`mdast-util-from-markdown`][mdast-util-from-markdown]
to enable MDX JSX.
###### Returns
Extension for `mdast-util-from-markdown` to enable MDX JSX
([`FromMarkdownExtension`][from-markdown-extension]).
When using the [micromark syntax extension][micromark-extension-mdx-jsx] with
`addResult`, nodes will have a `data.estree` field set to an ESTree
[`Program`][program] node.
### `mdxJsxToMarkdown(options?)`
Create an extension for
[`mdast-util-to-markdown`][mdast-util-to-markdown]
to enable MDX JSX.
This extension configures `mdast-util-to-markdown` with
[`options.fences: true`][mdast-util-to-markdown-fences] and
[`options.resourceLink: true`][mdast-util-to-markdown-resourcelink] too, do not
overwrite them!
###### Parameters
* `options` ([`ToMarkdownOptions`][api-to-markdown-options])
— configuration
###### Returns
Extension for `mdast-util-to-markdown` to enable MDX JSX
([`FromMarkdownExtension`][to-markdown-extension]).
### `MdxJsxAttribute`
MDX JSX attribute with a key (TypeScript type).
###### Type
```ts
import type {Literal} from 'mdast'
interface MdxJsxAttribute extends Literal {
type: 'mdxJsxAttribute'
name: string
value?: MdxJsxAttributeValueExpression | string | null | undefined
}
```
### `MdxJsxAttributeValueExpression`
MDX JSX attribute value set to an expression (TypeScript type).
###### Type
```ts
import type {Program} from 'estree-jsx'
import type {Literal} from 'mdast'
interface MdxJsxAttributeValueExpression extends Literal {
type: 'mdxJsxAttributeValueExpression'
data?: {estree?: Program | null | undefined} & Literal['data']
}
```
### `MdxJsxExpressionAttribute`
MDX JSX attribute as an expression (TypeScript type).
###### Type
```ts
import type {Program} from 'estree-jsx'
import type {Literal} from 'mdast'
interface MdxJsxExpressionAttribute extends Literal {
type: 'mdxJsxExpressionAttribute'
data?: {estree?: Program | null | undefined} & Literal['data']
}
```
### `MdxJsxFlowElement`
MDX JSX element node, occurring in flow (block) (TypeScript type).
###### Type
```ts
import type {BlockContent, DefinitionContent, Parent} from 'mdast'
export interface MdxJsxFlowElement extends Parent {
type: 'mdxJsxFlowElement'
name: string | null
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
children: Array<BlockContent | DefinitionContent>
}
```
### `MdxJsxFlowElementHast`
Same as [`MdxJsxFlowElement`][api-mdx-jsx-flow-element], but registered with
`@types/hast` (TypeScript type).
###### Type
```ts
import type {ElementContent, Parent} from 'hast'
export interface MdxJsxFlowElementHast extends Parent {
type: 'mdxJsxFlowElement'
name: string | null
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
children: Array<ElementContent>
}
```
### `MdxJsxTextElement`
MDX JSX element node, occurring in text (phrasing) (TypeScript type).
###### Type
```ts
import type {Parent, PhrasingContent} from 'mdast'
export interface MdxJsxTextElement extends Parent {
type: 'mdxJsxTextElement'
name: string | null
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
children: Array<PhrasingContent>
}
```
### `MdxJsxTextElementHast`
Same as [`MdxJsxTextElement`][api-mdx-jsx-text-element], but registered with
`@types/hast` (TypeScript type).
###### Type
```ts
import type {ElementContent, Parent} from 'hast'
export interface MdxJsxTextElementHast extends Parent {
type: 'mdxJsxTextElement'
name: string | null
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
children: Array<ElementContent>
}
```
### `ToMarkdownOptions`
Configuration (TypeScript type).
##### Fields
* `quote` (`'"'` or `"'"`, default: `'"'`)
— preferred quote to use around attribute values
* `quoteSmart` (`boolean`, default: `false`)
— use the other quote if that results in less bytes
* `tightSelfClosing` (`boolean`, default: `false`)
— do not use an extra space when closing self-closing elements: `<img/>`
instead of `<img />`
* `printWidth` (`number`, default: `Infinity`)
— try and wrap syntax at this width.
When set to a finite number (say, `80`), the formatter will print
attributes on separate lines when a tag doesnt fit on one line.
The normal behavior is to print attributes with spaces between them instead
of line endings
## HTML
MDX JSX has no representation in HTML.
Though, when you are dealing with MDX, you will likely go *through* hast.
You can enable passing MDX JSX through to hast by configuring
[`mdast-util-to-hast`][mdast-util-to-hast] with
`passThrough: ['mdxJsxFlowElement', 'mdxJsxTextElement']`.
## Syntax
See [Syntax in `micromark-extension-mdx-jsx`][syntax].
## Syntax tree
The following interfaces are added to **[mdast][]** by this utility.
### Nodes
#### `MdxJsxFlowElement`
```idl
interface MdxJsxFlowElement <: Parent {
type: "mdxJsxFlowElement"
}
MdxJsxFlowElement includes MdxJsxElement
```
**MdxJsxFlowElement** (**[Parent][dfn-parent]**) represents JSX in flow (block).
It can be used where **[flow][dfn-content-flow]** content is expected.
It includes the mixin **[MdxJsxElement][dfn-mixin-mdx-jsx-element]**.
For example, the following markdown:
```markdown
<w x="y">
z
</w>
```
Yields:
```js
{
type: 'mdxJsxFlowElement',
name: 'w',
attributes: [{type: 'mdxJsxAttribute', name: 'x', value: 'y'}],
children: [{type: 'paragraph', children: [{type: 'text', value: 'z'}]}]
}
```
#### `MdxJsxTextElement`
```idl
interface MdxJsxTextElement <: Parent {
type: "mdxJsxTextElement"
}
MdxJsxTextElement includes MdxJsxElement
```
**MdxJsxTextElement** (**[Parent][dfn-parent]**) represents JSX in text (span,
inline).
It can be used where **[phrasing][dfn-content-phrasing]** content is
expected.
It includes the mixin **[MdxJsxElement][dfn-mixin-mdx-jsx-element]**.
For example, the following markdown:
```markdown
a <b c>d</b> e.
```
Yields:
```js
{
type: 'mdxJsxTextElement',
name: 'b',
attributes: [{type: 'mdxJsxAttribute', name: 'c', value: null}],
children: [{type: 'text', value: 'd'}]
}
```
### Mixin
#### `MdxJsxElement`
```idl
interface mixin MdxJsxElement {
name: string?
attributes: [MdxJsxExpressionAttribute | MdxJsxAttribute]
}
interface MdxJsxExpressionAttribute <: Literal {
type: "mdxJsxExpressionAttribute"
}
interface MdxJsxAttribute <: Node {
type: "mdxJsxAttribute"
name: string
value: MdxJsxAttributeValueExpression | string?
}
interface MdxJsxAttributeValueExpression <: Literal {
type: "mdxJsxAttributeValueExpression"
}
```
**MdxJsxElement** represents a JSX element.
The `name` field can be present and represents an identifier.
Without `name`, the element represents a fragment, in which case no attributes
must be present.
The `attributes` field represents information associated with the node.
The value of the `attributes` field is a list of **MdxJsxExpressionAttribute**
and **MdxJsxAttribute** nodes.
**MdxJsxExpressionAttribute** represents an expression (typically in a
programming language) that when evaluated results in multiple attributes.
**MdxJsxAttribute** represents a single attribute.
The `name` field must be present.
The `value` field can be present, in which case it is either a string (a static
value) or an expression (typically in a programming language) that when
evaluated results in an attribute value.
### Content model
###### `FlowContent` (MDX JSX)
```idl
type MdxJsxFlowContent = MdxJsxFlowElement | FlowContent
```
###### `PhrasingContent` (MDX JSX)
```idl
type MdxJsxPhrasingContent = MdxJsxTextElement | PhrasingContent
```
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`MdxJsxAttribute`][api-mdx-jsx-attribute],
[`MdxJsxAttributeValueExpression`][api-mdx-jsx-attribute-value-expression],
[`MdxJsxExpressionAttribute`][api-mdx-jsx-expression-attribute],
[`MdxJsxFlowElement`][api-mdx-jsx-flow-element],
[`MdxJsxFlowElementHast`][api-mdx-jsx-flow-element-hast],
[`MdxJsxTextElement`][api-mdx-jsx-text-element],
[`MdxJsxTextElementHast`][api-mdx-jsx-text-element-hast], and
[`ToMarkdownOptions`][api-to-markdown-options].
It also registers the node types with `@types/mdast` and `@types/hast`.
If youre working with the syntax tree, make sure to import this utility
somewhere in your types, as that registers the new node types in the tree.
```js
/**
* @typedef {import('mdast-util-mdx-jsx')}
*/
import {visit} from 'unist-util-visit'
/** @type {import('mdast').Root} */
const tree = getMdastNodeSomeHow()
visit(tree, (node) => {
// `node` can now be one of the JSX nodes.
})
```
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with `mdast-util-from-markdown` version 1+ and
`mdast-util-to-markdown` version 1+.
## Related
* [`micromark/micromark-extension-mdx-jsx`][micromark-extension-mdx-jsx]
— support MDX JSX in micromark
* [`syntax-tree/mdast-util-mdx`][mdast-util-mdx]
— support MDX in mdast
* [`remarkjs/remark-mdx`][remark-mdx]
— support MDX in remark
## Contribute
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/syntax-tree/mdast-util-mdx-jsx/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/mdast-util-mdx-jsx/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-mdx-jsx.svg
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-mdx-jsx
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-mdx-jsx.svg
[downloads]: https://www.npmjs.com/package/mdast-util-mdx-jsx
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-mdx-jsx.svg
[size]: https://bundlephobia.com/result?p=mdast-util-mdx-jsx
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[esmsh]: https://esm.sh
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[typescript]: https://www.typescriptlang.org
[mdast]: https://github.com/syntax-tree/mdast
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast
[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options
[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx
[program]: https://github.com/estree/estree/blob/master/es2015.md#programs
[dfn-parent]: https://github.com/syntax-tree/mdast#parent
[dfn-content-flow]: #flowcontent-mdx-jsx
[dfn-content-phrasing]: #phrasingcontent-mdx-jsx
[dfn-mixin-mdx-jsx-element]: #mdxjsxelement
[jsx]: https://facebook.github.io/jsx/
[what-is-mdx]: https://mdxjs.com/docs/what-is-mdx/
[micromark-extension-mdx-jsx]: https://github.com/micromark/micromark-extension-mdx-jsx
[syntax]: https://github.com/micromark/micromark-extension-mdx-jsx#syntax
[mdast-util-to-markdown-fences]: https://github.com/syntax-tree/mdast-util-to-markdown#optionsfences
[mdast-util-to-markdown-resourcelink]: https://github.com/syntax-tree/mdast-util-to-markdown#optionsresourcelink
[remark-mdx]: https://mdxjs.com/packages/remark-mdx/
[mdx]: https://mdxjs.com
[api-mdx-jsx-from-markdown]: #mdxjsxfrommarkdown
[api-mdx-jsx-to-markdown]: #mdxjsxtomarkdownoptions
[api-mdx-jsx-attribute]: #mdxjsxattribute
[api-mdx-jsx-attribute-value-expression]: #mdxjsxattributevalueexpression
[api-mdx-jsx-expression-attribute]: #mdxjsxexpressionattribute
[api-mdx-jsx-flow-element]: #mdxjsxflowelement
[api-mdx-jsx-flow-element-hast]: #mdxjsxflowelementhast
[api-mdx-jsx-text-element]: #mdxjsxtextelement
[api-mdx-jsx-text-element-hast]: #mdxjsxtextelementhast
[api-to-markdown-options]: #tomarkdownoptions