This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

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

@@ -0,0 +1,346 @@
import type {Program} from 'estree-jsx'
import type {Data as HastData, ElementContent, Parent as HastParent} from 'hast'
import type {
BlockContent,
Data as MdastData,
DefinitionContent,
Literal as MdastLiteral,
Node as MdastNode,
Parent as MdastParent,
PhrasingContent
} from 'mdast'
import type {Data, Node} from 'unist'
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} />
* ^^^
* ```
*/
export interface MdxJsxAttributeValueExpression extends Node {
/**
* Node type.
*/
type: 'mdxJsxAttributeValueExpression'
/**
* Value.
*/
value: string
/**
* Data associated with the mdast MDX JSX attribute value expression.
*/
data?: MdxJsxAttributeValueExpressionData | undefined
}
/**
* Info associated with mdast MDX JSX attribute value expression nodes by the
* ecosystem.
*/
export interface MdxJsxAttributeValueExpressionData extends Data {
/**
* Program node from estree.
*/
estree?: Program | null | undefined
}
/**
* MDX JSX attribute as an expression.
*
* ```markdown
* > | <a {...b} />
* ^^^^^^
* ```
*/
export interface MdxJsxExpressionAttribute extends Node {
/**
* Node type.
*/
type: 'mdxJsxExpressionAttribute'
/**
* Value.
*/
value: string
/**
* Data associated with the mdast MDX JSX expression attributes.
*/
data?: MdxJsxExpressionAttributeData | undefined
}
/**
* Info associated with mdast MDX JSX expression attribute nodes by the
* ecosystem.
*/
export interface MdxJsxExpressionAttributeData extends Data {
/**
* Program node from estree.
*/
estree?: Program | null | undefined
}
/**
* MDX JSX attribute with a key.
*
* ```markdown
* > | <a b="c" />
* ^^^^^
* ```
*/
export interface MdxJsxAttribute extends Node {
/**
* Node type.
*/
type: 'mdxJsxAttribute'
/**
* Attribute name.
*/
name: string
/**
* Attribute value.
*/
value?: MdxJsxAttributeValueExpression | string | null | undefined
/**
* Data associated with the mdast MDX JSX attribute.
*/
data?: MdxJsxAttributeData | undefined
}
/**
* Info associated with mdast MDX JSX attribute nodes by the
* ecosystem.
*/
export interface MdxJsxAttributeData extends Data {}
/**
* MDX JSX element node, occurring in flow (block).
*/
export interface MdxJsxFlowElement extends MdastParent {
/**
* Node type.
*/
type: 'mdxJsxFlowElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: Array<BlockContent | DefinitionContent>
/**
* Data associated with the mdast MDX JSX elements (flow).
*/
data?: MdxJsxFlowElementData | undefined
}
/**
* Info associated with mdast MDX JSX element (flow) nodes by the
* ecosystem.
*/
export interface MdxJsxFlowElementData extends MdastData {}
/**
* MDX JSX element node, occurring in text (phrasing).
*/
export interface MdxJsxTextElement extends MdastParent {
/**
* Node type.
*/
type: 'mdxJsxTextElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: PhrasingContent[]
/**
* Data associated with the mdast MDX JSX elements (text).
*/
data?: MdxJsxTextElementData | undefined
}
/**
* Info associated with mdast MDX JSX element (text) nodes by the
* ecosystem.
*/
export interface MdxJsxTextElementData extends MdastData {}
/**
* MDX JSX element node, occurring in flow (block), for hast.
*/
export interface MdxJsxFlowElementHast extends HastParent {
/**
* Node type.
*/
type: 'mdxJsxFlowElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: ElementContent[]
/**
* Data associated with the hast MDX JSX elements (flow).
*/
data?: MdxJsxFlowElementHastData | undefined
}
/**
* Info associated with hast MDX JSX element (flow) nodes by the
* ecosystem.
*/
export interface MdxJsxFlowElementHastData extends HastData {}
/**
* MDX JSX element node, occurring in text (phrasing), for hast.
*/
export interface MdxJsxTextElementHast extends HastParent {
/**
* Node type.
*/
type: 'mdxJsxTextElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: ElementContent[]
/**
* Data associated with the hast MDX JSX elements (text).
*/
data?: MdxJsxTextElementHastData | undefined
}
/**
* Info associated with hast MDX JSX element (text) nodes by the
* ecosystem.
*/
export interface MdxJsxTextElementHastData extends HastData {}
// Add nodes to mdast content.
declare module 'mdast' {
interface BlockContentMap {
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElement
}
interface PhrasingContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElement
}
interface RootContentMap {
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElement
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElement
}
}
// Add nodes to hast content.
declare module 'hast' {
interface ElementContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElementHast
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElementHast
}
interface RootContentMap {
/**
* 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' {
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' {
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'

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

@@ -0,0 +1,99 @@
/**
* 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 (optional).
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable MDX JSX.
*/
export function mdxJsxToMarkdown(options?: ToMarkdownOptions | null | undefined): ToMarkdownExtension;
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 OnEnterError = import('mdast-util-from-markdown').OnEnterError;
export type OnExitError = import('mdast-util-from-markdown').OnExitError;
export type Token = import('mdast-util-from-markdown').Token;
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 Point = import('unist').Point;
export type MdxJsxAttribute = import('../index.js').MdxJsxAttribute;
export type MdxJsxAttributeValueExpression = import('../index.js').MdxJsxAttributeValueExpression;
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 (default: `'"'`).
*/
quote?: '"' | "'" | null | undefined;
/**
* Use the other quote if that results in less bytes (default: `false`).
*/
quoteSmart?: boolean | null | undefined;
/**
* Do not use an extra space when closing self-closing elements: `<img/>`
* instead of `<img />` (default: `false`).
*/
tightSelfClosing?: boolean | null | undefined;
/**
* Try and wrap syntax at this width (default: `Infinity`).
*
* 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;
};
//# sourceMappingURL=index.d.ts.map

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

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAoEA;;;;;;;;GAQG;AACH,sCANa,qBAAqB,CAsbjC;AAED;;;;;;;;;;;GAWG;AACH,2CALW,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAElC,mBAAmB,CAyL/B;6BAhsBY,OAAO,0BAA0B,EAAE,cAAc;oCACjD,OAAO,0BAA0B,EAAE,SAAS;iCAC5C,OAAO,0BAA0B,EAAE,MAAM;2BACzC,OAAO,0BAA0B,EAAE,YAAY;0BAC/C,OAAO,0BAA0B,EAAE,WAAW;oBAC9C,OAAO,0BAA0B,EAAE,KAAK;+BAExC,OAAO,wBAAwB,EAAE,MAAM;kCACvC,OAAO,wBAAwB,EAAE,OAAO;oBACxC,OAAO,wBAAwB,EAAE,KAAK;sBACtC,OAAO,wBAAwB,EAAE,OAAO;oBAExC,OAAO,OAAO,EAAE,KAAK;8BAErB,OAAO,aAAa,EAAE,eAAe;6CACrC,OAAO,aAAa,EAAE,8BAA8B;wCACpD,OAAO,aAAa,EAAE,yBAAyB;gCAC/C,OAAO,aAAa,EAAE,iBAAiB;gCACvC,OAAO,aAAa,EAAE,iBAAiB;;;;;;;;;;;UAMtC,MAAM,GAAG,SAAS;;;;gBAKlB,MAAM,eAAe,GAAG,yBAAyB,CAAC;;;;WAElD,OAAO;;;;iBAEP,OAAO;;;;WAEP,KAAK,CAAC,OAAO,CAAC;;;;SAEd,KAAK,CAAC,OAAO,CAAC;;;;;;;;;YAKd,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS;;;;iBAE5B,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;uBAE1B,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;;;;;iBAG1B,MAAM,GAAG,IAAI,GAAG,SAAS"}

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

@@ -0,0 +1,798 @@
/**
* @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').OnEnterError} OnEnterError
* @typedef {import('mdast-util-from-markdown').OnExitError} OnExitError
* @typedef {import('mdast-util-from-markdown').Token} Token
*
* @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('unist').Point} Point
*
* @typedef {import('../index.js').MdxJsxAttribute} MdxJsxAttribute
* @typedef {import('../index.js').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
* @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 (default: `'"'`).
* @property {boolean | null | undefined} [quoteSmart=false]
* Use the other quote if that results in less bytes (default: `false`).
* @property {boolean | null | undefined} [tightSelfClosing=false]
* Do not use an extra space when closing self-closing elements: `<img/>`
* instead of `<img />` (default: `false`).
* @property {number | null | undefined} [printWidth=Infinity]
* Try and wrap syntax at this width (default: `Infinity`).
*
* 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 {ok as assert} from 'devlop'
import {parseEntities} from 'parse-entities'
import {stringifyEntitiesLight} from 'stringify-entities'
import {stringifyPosition} from 'unist-util-stringify-position'
import {VFileMessage} from 'vfile-message'
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()
}
/**
* Copy a point-like value.
*
* @param {Point} d
* Point-like value.
* @returns {Point}
* unist point.
*/
function point(d) {
return {line: d.line, column: d.column, offset: d.offset}
}
/**
* @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.data.mdxJsxTagStack) this.data.mdxJsxTagStack = []
this.data.mdxJsxTag = tag
this.buffer()
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagClosingMarker(token) {
const stack = this.data.mdxJsxTagStack
assert(stack, 'expected `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 = this.data.mdxJsxTag
assert(tag, 'expected `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 = this.data.mdxJsxTag
assert(tag, 'expected `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 = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
tag.close = true
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagNamePrimary(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
tag.name = this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagNameMember(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
tag.name += '.' + this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagNameLocal(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
tag.name += ':' + this.sliceSerialize(token)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagAttribute(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
enterMdxJsxTagAnyAttribute.call(this, token)
tag.attributes.push({
type: 'mdxJsxAttribute',
name: '',
value: null,
position: {
start: point(token.start),
// @ts-expect-error: `end` will be patched later.
end: undefined
}
})
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTagExpressionAttribute(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
enterMdxJsxTagAnyAttribute.call(this, token)
tag.attributes.push({type: 'mdxJsxExpressionAttribute', value: ''})
this.buffer()
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagExpressionAttribute(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const tail = tag.attributes[tag.attributes.length - 1]
assert(tail.type === 'mdxJsxExpressionAttribute')
const estree = token.estree
tail.value = this.resume()
if (estree) {
tail.data = {estree}
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeNamePrimary(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const node = tag.attributes[tag.attributes.length - 1]
assert(node.type === 'mdxJsxAttribute')
node.name = this.sliceSerialize(token)
assert(node.position !== undefined)
node.position.end = point(token.end)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeNameLocal(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const node = tag.attributes[tag.attributes.length - 1]
assert(node.type === 'mdxJsxAttribute')
node.name += ':' + this.sliceSerialize(token)
assert(node.position !== undefined)
node.position.end = point(token.end)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeValueLiteral(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const node = tag.attributes[tag.attributes.length - 1]
node.value = parseEntities(this.resume(), {nonTerminated: false})
assert(node.position !== undefined)
node.position.end = point(token.end)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagAttributeValueExpression(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const tail = tag.attributes[tag.attributes.length - 1]
assert(tail.type === 'mdxJsxAttribute')
/** @type {MdxJsxAttributeValueExpression} */
const node = {type: 'mdxJsxAttributeValueExpression', value: this.resume()}
const estree = token.estree
if (estree) {
node.data = {estree}
}
tail.value = node
assert(tail.position !== undefined)
tail.position.end = point(token.end)
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTagSelfClosingMarker() {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
tag.selfClosing = true
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitMdxJsxTag(token) {
const tag = this.data.mdxJsxTag
assert(tag, 'expected `mdxJsxTag`')
const stack = this.data.mdxJsxTagStack
assert(stack, 'expected `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 stack = this.data.mdxJsxTagStack
assert(stack, 'expected `mdxJsxTagStack`')
const tag = stack[stack.length - 1]
assert(tag, 'expected `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 = this.data.mdxJsxTag
assert(tag, 'expected `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 (optional).
* @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, _, state, info) {
const flow = node.type === 'mdxJsxFlowElement'
const selfClosing = node.name
? !node.children || node.children.length === 0
: false
const depth = inferDepth(state)
const currentIndent = createIndent(depth)
const trackerOneLine = state.createTracker(info)
const trackerMultiLine = state.createTracker(info)
/** @type {Array<string>} */
const serializedAttributes = []
const prefix = (flow ? currentIndent : '') + '<' + (node.name || '')
const exit = state.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 === null || value === undefined) {
// 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(
// @ts-expect-error: `containerPhrasing` is typed correctly, but TS
// generates *hardcoded* types, which means that our dynamically added
// directives are not present.
// At some point, TS should fix that, and `from-markdown` should be fine.
state.containerPhrasing(node, {
...tracker.current(),
before: '>',
after: '<'
})
)
} else {
tracker.shift(2)
value += tracker.move('\n')
value += tracker.move(containerFlow(node, state, 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
: state.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} state
* @returns {number}
*/
function inferDepth(state) {
let depth = 0
let index = state.stack.length
while (--index > -1) {
const name = state.stack[index]
if (name === 'blockquote' || name === 'listItem') break
if (name === '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.

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

@@ -0,0 +1,113 @@
{
"name": "mdast-util-mdx-jsx",
"version": "3.1.2",
"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",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts.map",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree-jsx": "^1.0.0",
"@types/hast": "^3.0.0",
"@types/mdast": "^4.0.0",
"@types/unist": "^3.0.0",
"ccount": "^2.0.0",
"devlop": "^1.1.0",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-to-markdown": "^2.0.0",
"parse-entities": "^4.0.0",
"stringify-entities": "^4.0.0",
"unist-util-remove-position": "^5.0.0",
"unist-util-stringify-position": "^4.0.0",
"vfile-message": "^4.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"acorn": "^8.0.0",
"c8": "^9.0.0",
"micromark-extension-mdx-jsx": "^3.0.0",
"micromark-extension-mdx-md": "^2.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.58.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api-prod": "node --conditions production test.js",
"test-api-dev": "node --conditions development test.js",
"test-api": "npm run test-api-dev && npm run test-api-prod",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"bracketSpacing": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-definitions": "off"
}
}
],
"prettier": true,
"rules": {
"logical-assignment-operators": "off",
"unicorn/prefer-at": "off"
}
}
}

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

@@ -0,0 +1,718 @@
# 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 16+), 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@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@3?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 {mdxJsx} from 'micromark-extension-mdx-jsx'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'mdast-util-mdx-jsx'
import {toMarkdown} from 'mdast-util-to-markdown'
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, function (node) {
// `node` can now be one of the JSX nodes.
})
```
## Compatibility
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, `mdast-util-mdx-jsx@^3`,
compatible with Node.js 16.
This utility works with `mdast-util-from-markdown` version 2+ and
`mdast-util-to-markdown` version 2+.
## 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/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-mdx-jsx
[size]: https://bundlejs.com/?q=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