🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
9
node_modules/mdast-util-mdx-expression/complex-types.d.ts
generated
vendored
Normal file
9
node_modules/mdast-util-mdx-expression/complex-types.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// To do: next major: remove this file.
|
||||
export type {
|
||||
MdxFlowExpression,
|
||||
MdxTextExpression,
|
||||
MDXFlowExpression,
|
||||
MDXTextExpression
|
||||
} from './index.js'
|
||||
|
||||
/// <reference types="./index.js" />
|
||||
154
node_modules/mdast-util-mdx-expression/index.d.ts
generated
vendored
Normal file
154
node_modules/mdast-util-mdx-expression/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
import type {Program} from 'estree-jsx'
|
||||
import type {Literal as HastLiteral} from 'hast'
|
||||
import type {Literal as MdastLiteral} from 'mdast'
|
||||
|
||||
export {
|
||||
mdxExpressionFromMarkdown,
|
||||
mdxExpressionToMarkdown
|
||||
} from './lib/index.js'
|
||||
|
||||
/**
|
||||
* MDX expression node, occurring in flow (block).
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface MdxFlowExpression extends MdastLiteral {
|
||||
/**
|
||||
* Node type.
|
||||
*/
|
||||
type: 'mdxFlowExpression'
|
||||
|
||||
/**
|
||||
* Data.
|
||||
*/
|
||||
data?: {
|
||||
/**
|
||||
* Program node from estree.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
estree?: Program | null | undefined
|
||||
} & MdastLiteral['data']
|
||||
}
|
||||
|
||||
/**
|
||||
* MDX expression node, occurring in text (phrasing).
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface MdxTextExpression extends MdastLiteral {
|
||||
/**
|
||||
* Node type.
|
||||
*/
|
||||
type: 'mdxTextExpression'
|
||||
|
||||
/**
|
||||
* Data.
|
||||
*/
|
||||
data?: {
|
||||
/**
|
||||
* Program node from estree.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
estree?: Program | null | undefined
|
||||
} & MdastLiteral['data']
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use `MdxFlowExpression`.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export type MDXFlowExpression = MdxFlowExpression
|
||||
|
||||
/**
|
||||
* Deprecated: use `MdxTextExpression`.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export type MDXTextExpression = MdxTextExpression
|
||||
|
||||
/**
|
||||
* MDX expression node, occurring in flow (block), for hast.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface MdxFlowExpressionHast extends HastLiteral {
|
||||
/**
|
||||
* Node type.
|
||||
*/
|
||||
type: 'mdxFlowExpression'
|
||||
|
||||
/**
|
||||
* Data.
|
||||
*/
|
||||
data?: {
|
||||
/**
|
||||
* Program node from estree.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
estree?: Program | null | undefined
|
||||
} & HastLiteral['data']
|
||||
}
|
||||
|
||||
/**
|
||||
* MDX expression node, occurring in text (phrasing), for hast.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface MdxTextExpressionHast extends HastLiteral {
|
||||
/**
|
||||
* Node type.
|
||||
*/
|
||||
type: 'mdxTextExpression'
|
||||
|
||||
/**
|
||||
* Data.
|
||||
*/
|
||||
data?: {
|
||||
/**
|
||||
* Program node from estree.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
estree?: Program | null | undefined
|
||||
} & HastLiteral['data']
|
||||
}
|
||||
|
||||
// Add nodes to mdast content.
|
||||
declare module 'mdast' {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
interface StaticPhrasingContentMap {
|
||||
/**
|
||||
* MDX expression node, occurring in text (phrasing).
|
||||
*/
|
||||
mdxTextExpression: MdxTextExpression
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
interface BlockContentMap {
|
||||
/**
|
||||
* MDX expression node, occurring in flow (block).
|
||||
*/
|
||||
mdxFlowExpression: MdxFlowExpression
|
||||
}
|
||||
}
|
||||
|
||||
// Add nodes to hast content.
|
||||
declare module 'hast' {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
interface RootContentMap {
|
||||
/**
|
||||
* MDX expression node, occurring in flow (block).
|
||||
*/
|
||||
mdxFlowExpression: MdxFlowExpressionHast
|
||||
/**
|
||||
* MDX expression node, occurring in text (phrasing).
|
||||
*/
|
||||
mdxTextExpression: MdxTextExpressionHast
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
interface ElementContentMap {
|
||||
/**
|
||||
* MDX expression node, occurring in flow (block).
|
||||
*/
|
||||
mdxFlowExpression: MdxFlowExpressionHast
|
||||
/**
|
||||
* MDX expression node, occurring in text (phrasing).
|
||||
*/
|
||||
mdxTextExpression: MdxTextExpressionHast
|
||||
}
|
||||
}
|
||||
5
node_modules/mdast-util-mdx-expression/index.js
generated
vendored
Normal file
5
node_modules/mdast-util-mdx-expression/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// Note: types exposed from `index.d.ts`.
|
||||
export {
|
||||
mdxExpressionFromMarkdown,
|
||||
mdxExpressionToMarkdown
|
||||
} from './lib/index.js'
|
||||
36
node_modules/mdast-util-mdx-expression/lib/index.d.ts
generated
vendored
Normal file
36
node_modules/mdast-util-mdx-expression/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* @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-to-markdown').Options} ToMarkdownExtension
|
||||
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
|
||||
*
|
||||
* @typedef {import('../index.js').MdxFlowExpression} MdxFlowExpression
|
||||
* @typedef {import('../index.js').MdxTextExpression} MdxTextExpression
|
||||
*/
|
||||
/**
|
||||
* Extension for `mdast-util-from-markdown` to enable MDX expressions.
|
||||
*
|
||||
* When using the syntax extension with `addResult`, nodes will have a
|
||||
* `data.estree` field set to an ESTree `Program` node.
|
||||
*
|
||||
* @type {FromMarkdownExtension}
|
||||
*/
|
||||
export const mdxExpressionFromMarkdown: FromMarkdownExtension
|
||||
/**
|
||||
* Extension for `mdast-util-to-markdown` to enable MDX ESM.
|
||||
*
|
||||
* @type {ToMarkdownExtension}
|
||||
*/
|
||||
export const mdxExpressionToMarkdown: 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 ToMarkdownExtension = import('mdast-util-to-markdown').Options
|
||||
export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle
|
||||
export type MdxFlowExpression = import('../index.js').MdxFlowExpression
|
||||
export type MdxTextExpression = import('../index.js').MdxTextExpression
|
||||
105
node_modules/mdast-util-mdx-expression/lib/index.js
generated
vendored
Normal file
105
node_modules/mdast-util-mdx-expression/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
* @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-to-markdown').Options} ToMarkdownExtension
|
||||
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
|
||||
*
|
||||
* @typedef {import('../index.js').MdxFlowExpression} MdxFlowExpression
|
||||
* @typedef {import('../index.js').MdxTextExpression} MdxTextExpression
|
||||
*/
|
||||
|
||||
/**
|
||||
* Extension for `mdast-util-from-markdown` to enable MDX expressions.
|
||||
*
|
||||
* When using the syntax extension with `addResult`, nodes will have a
|
||||
* `data.estree` field set to an ESTree `Program` node.
|
||||
*
|
||||
* @type {FromMarkdownExtension}
|
||||
*/
|
||||
export const mdxExpressionFromMarkdown = {
|
||||
enter: {
|
||||
mdxFlowExpression: enterMdxFlowExpression,
|
||||
mdxTextExpression: enterMdxTextExpression
|
||||
},
|
||||
exit: {
|
||||
mdxFlowExpression: exitMdxExpression,
|
||||
mdxFlowExpressionChunk: exitMdxExpressionData,
|
||||
mdxTextExpression: exitMdxExpression,
|
||||
mdxTextExpressionChunk: exitMdxExpressionData
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for `mdast-util-to-markdown` to enable MDX ESM.
|
||||
*
|
||||
* @type {ToMarkdownExtension}
|
||||
*/
|
||||
export const mdxExpressionToMarkdown = {
|
||||
handlers: {
|
||||
mdxFlowExpression: handleMdxExpression,
|
||||
mdxTextExpression: handleMdxExpression
|
||||
},
|
||||
unsafe: [
|
||||
{character: '{', inConstruct: ['phrasing']},
|
||||
{atBreak: true, character: '{'}
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {FromMarkdownHandle}
|
||||
*/
|
||||
function enterMdxFlowExpression(token) {
|
||||
this.enter({type: 'mdxFlowExpression', value: ''}, token)
|
||||
this.buffer()
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {FromMarkdownHandle}
|
||||
*/
|
||||
function enterMdxTextExpression(token) {
|
||||
this.enter({type: 'mdxTextExpression', value: ''}, token)
|
||||
this.buffer()
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {FromMarkdownHandle}
|
||||
*/
|
||||
function exitMdxExpression(token) {
|
||||
const value = this.resume()
|
||||
/** @type {Program | undefined} */
|
||||
// @ts-expect-error: estree.
|
||||
const estree = token.estree
|
||||
const node = /** @type {MdxFlowExpression | MdxTextExpression} */ (
|
||||
this.exit(token)
|
||||
)
|
||||
node.value = value
|
||||
|
||||
if (estree) {
|
||||
node.data = {estree}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {FromMarkdownHandle}
|
||||
*/
|
||||
function exitMdxExpressionData(token) {
|
||||
this.config.enter.data.call(this, token)
|
||||
this.config.exit.data.call(this, token)
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {ToMarkdownHandle}
|
||||
* @param {MdxFlowExpression | MdxTextExpression} node
|
||||
*/
|
||||
function handleMdxExpression(node) {
|
||||
const value = node.value || ''
|
||||
return '{' + value + '}'
|
||||
}
|
||||
22
node_modules/mdast-util-mdx-expression/license
generated
vendored
Normal file
22
node_modules/mdast-util-mdx-expression/license
generated
vendored
Normal 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.
|
||||
90
node_modules/mdast-util-mdx-expression/package.json
generated
vendored
Normal file
90
node_modules/mdast-util-mdx-expression/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
{
|
||||
"name": "mdast-util-mdx-expression",
|
||||
"version": "1.3.2",
|
||||
"description": "mdast extension to parse and serialize MDX (or MDX.js) expressions",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"mdast",
|
||||
"mdast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"markdown",
|
||||
"markup",
|
||||
"mdx",
|
||||
"mdxjs",
|
||||
"expression",
|
||||
"extension"
|
||||
],
|
||||
"repository": "syntax-tree/mdast-util-mdx-expression",
|
||||
"bugs": "https://github.com/syntax-tree/mdast-util-mdx-expression/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/",
|
||||
"complex-types.d.ts",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/estree-jsx": "^1.0.0",
|
||||
"@types/hast": "^2.0.0",
|
||||
"@types/mdast": "^3.0.0",
|
||||
"mdast-util-from-markdown": "^1.0.0",
|
||||
"mdast-util-to-markdown": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/acorn": "^4.0.0",
|
||||
"@types/node": "^18.0.0",
|
||||
"acorn": "^8.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"micromark-extension-mdx-expression": "^1.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^4.0.0",
|
||||
"unist-util-remove-position": "^4.0.0",
|
||||
"xo": "^0.53.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
|
||||
}
|
||||
}
|
||||
497
node_modules/mdast-util-mdx-expression/readme.md
generated
vendored
Normal file
497
node_modules/mdast-util-mdx-expression/readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,497 @@
|
|||
# mdast-util-mdx-expression
|
||||
|
||||
[![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][] expressions (`{Math.PI}`).
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When to use this](#when-to-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`mdxExpressionFromMarkdown`](#mdxexpressionfrommarkdown)
|
||||
* [`mdxExpressionToMarkdown`](#mdxexpressiontomarkdown)
|
||||
* [`MdxFlowExpression`](#mdxflowexpression)
|
||||
* [`MdxTextExpression`](#mdxtextexpression)
|
||||
* [`MdxFlowExpressionHast`](#mdxflowexpressionhast)
|
||||
* [`MdxTextExpressionHast`](#mdxtextexpressionhast)
|
||||
* [HTML](#html)
|
||||
* [Syntax](#syntax)
|
||||
* [Syntax tree](#syntax-tree)
|
||||
* [Nodes](#nodes)
|
||||
* [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 expression syntax
|
||||
in markdown to [mdast][].
|
||||
These extensions plug into
|
||||
[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing
|
||||
expressions in markdown into a syntax tree) and
|
||||
[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing
|
||||
expressions in syntax trees to markdown).
|
||||
|
||||
## 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-expression`][extension].
|
||||
|
||||
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-expression
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {mdxExpressionFromMarkdown, mdxExpressionToMarkdown} from 'https://esm.sh/mdast-util-mdx-expression@1'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {mdxExpressionFromMarkdown, mdxExpressionToMarkdown} from 'https://esm.sh/mdast-util-mdx-expression@1?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
Say our document `example.mdx` contains:
|
||||
|
||||
```mdx
|
||||
{
|
||||
a + 1
|
||||
}
|
||||
|
||||
b {true}.
|
||||
```
|
||||
|
||||
…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 {mdxExpression} from 'micromark-extension-mdx-expression'
|
||||
import {mdxExpressionFromMarkdown, mdxExpressionToMarkdown} from 'mdast-util-mdx-expression'
|
||||
|
||||
const doc = await fs.readFile('example.mdx')
|
||||
|
||||
const tree = fromMarkdown(doc, {
|
||||
extensions: [mdxExpression({acorn, addResult: true})],
|
||||
mdastExtensions: [mdxExpressionFromMarkdown]
|
||||
})
|
||||
|
||||
console.log(tree)
|
||||
|
||||
const out = toMarkdown(tree, {extensions: [mdxExpressionToMarkdown]})
|
||||
|
||||
console.log(out)
|
||||
```
|
||||
|
||||
…now running `node example.js` yields (positional info removed for brevity):
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'root',
|
||||
children: [
|
||||
{
|
||||
type: 'mdxFlowExpression',
|
||||
value: '\na + 1\n',
|
||||
data: {
|
||||
estree: {
|
||||
type: 'Program',
|
||||
body: [
|
||||
{
|
||||
type: 'ExpressionStatement',
|
||||
expression: {
|
||||
type: 'BinaryExpression',
|
||||
left: {type: 'Identifier', name: 'a'},
|
||||
operator: '+',
|
||||
right: {type: 'Literal', value: 1, raw: '1'}
|
||||
}
|
||||
}
|
||||
],
|
||||
sourceType: 'module'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'paragraph',
|
||||
children: [
|
||||
{type: 'text', value: 'b '},
|
||||
{
|
||||
type: 'mdxTextExpression',
|
||||
value: 'true',
|
||||
data: {
|
||||
estree: {
|
||||
type: 'Program',
|
||||
body: [
|
||||
{
|
||||
type: 'ExpressionStatement',
|
||||
expression: {type: 'Literal', value: true, raw: 'true'}
|
||||
}
|
||||
],
|
||||
sourceType: 'module'
|
||||
}
|
||||
}
|
||||
},
|
||||
{type: 'text', value: '.'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```markdown
|
||||
{
|
||||
a + 1
|
||||
}
|
||||
|
||||
b {true}.
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the identifiers
|
||||
[`mdxExpressionFromMarkdown`][api-mdx-expression-from-markdown] and
|
||||
[`mdxExpressionToMarkdown`][api-mdx-expression-to-markdown].
|
||||
There is no default export.
|
||||
|
||||
### `mdxExpressionFromMarkdown`
|
||||
|
||||
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable
|
||||
MDX expressions.
|
||||
|
||||
When using the [micromark syntax extension][extension] with `addResult`, nodes
|
||||
will have a `data.estree` field set to an ESTree [`Program`][program] node.
|
||||
|
||||
### `mdxExpressionToMarkdown`
|
||||
|
||||
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable MDX
|
||||
expressions.
|
||||
|
||||
### `MdxFlowExpression`
|
||||
|
||||
MDX expression node, occurring in flow (block) (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
import type {Program} from 'estree-jsx'
|
||||
import type {Literal} from 'mdast'
|
||||
|
||||
interface MdxFlowExpression extends Literal {
|
||||
type: 'mdxFlowExpression'
|
||||
data?: {estree?: Program | null | undefined} & Literal['data']
|
||||
}
|
||||
```
|
||||
|
||||
### `MdxTextExpression`
|
||||
|
||||
MDX expression node, occurring in text (block) (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
import type {Program} from 'estree-jsx'
|
||||
import type {Literal} from 'mdast'
|
||||
|
||||
interface MdxTextExpression extends Literal {
|
||||
type: 'mdxTextExpression'
|
||||
data?: {estree?: Program | null | undefined} & Literal['data']
|
||||
}
|
||||
```
|
||||
|
||||
### `MdxFlowExpressionHast`
|
||||
|
||||
Same as [`MdxFlowExpression`][api-mdx-flow-expression], but registered with
|
||||
`@types/hast` (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
import type {Program} from 'estree-jsx'
|
||||
import type {Literal} from 'hast'
|
||||
|
||||
interface MdxFlowExpressionHast extends Literal {
|
||||
type: 'mdxFlowExpression'
|
||||
data?: {estree?: Program | null | undefined} & Literal['data']
|
||||
}
|
||||
```
|
||||
|
||||
### `MdxTextExpressionHast`
|
||||
|
||||
Same as [`MdxTextExpression`][api-mdx-text-expression], but registered with
|
||||
`@types/hast` (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
import type {Program} from 'estree-jsx'
|
||||
import type {Literal} from 'hast'
|
||||
|
||||
interface MdxTextExpressionHast extends Literal {
|
||||
type: 'mdxTextExpression'
|
||||
data?: {estree?: Program | null | undefined} & Literal['data']
|
||||
}
|
||||
```
|
||||
|
||||
## HTML
|
||||
|
||||
MDX expressions have no representation in HTML.
|
||||
Though, when you are dealing with MDX, you will likely go *through* hast.
|
||||
You can enable passing MDX expressions through to hast by configuring
|
||||
[`mdast-util-to-hast`][mdast-util-to-hast] with
|
||||
`passThrough: ['mdxFlowExpression', 'mdxTextExpression']`.
|
||||
|
||||
## Syntax
|
||||
|
||||
See [Syntax in `micromark-extension-mdx-expression`][syntax].
|
||||
|
||||
## Syntax tree
|
||||
|
||||
The following interfaces are added to **[mdast][]** by this utility.
|
||||
|
||||
### Nodes
|
||||
|
||||
#### `MdxFlowExpression`
|
||||
|
||||
```idl
|
||||
interface MdxFlowExpression <: Literal {
|
||||
type: "mdxFlowExpression"
|
||||
}
|
||||
```
|
||||
|
||||
**MdxFlowExpression** (**[Literal][dfn-literal]**) represents a JavaScript
|
||||
expression embedded in flow (block).
|
||||
It can be used where **[flow][dfn-flow-content]** content is expected.
|
||||
Its content is represented by its `value` field.
|
||||
|
||||
For example, the following markdown:
|
||||
|
||||
```markdown
|
||||
{
|
||||
1 + 1
|
||||
}
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
{type: 'mdxFlowExpression', value: '\n1 + 1\n'}
|
||||
```
|
||||
|
||||
#### `MdxTextExpression`
|
||||
|
||||
```idl
|
||||
interface MdxTextExpression <: Literal {
|
||||
type: "mdxTextExpression"
|
||||
}
|
||||
```
|
||||
|
||||
**MdxTextExpression** (**[Literal][dfn-literal]**) represents a JavaScript
|
||||
expression embedded in text (span, inline).
|
||||
It can be used where **[phrasing][dfn-phrasing-content]** content is expected.
|
||||
Its content is represented by its `value` field.
|
||||
|
||||
For example, the following markdown:
|
||||
|
||||
```markdown
|
||||
a {1 + 1} b.
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
{type: 'mdxTextExpression', value: '1 + 1'}
|
||||
```
|
||||
|
||||
### Content model
|
||||
|
||||
#### `FlowContent` (MDX expression)
|
||||
|
||||
```idl
|
||||
type FlowContentMdxExpression = MdxFlowExpression | FlowContent
|
||||
```
|
||||
|
||||
#### `PhrasingContent` (MDX expression)
|
||||
|
||||
```idl
|
||||
type PhrasingContentMdxExpression = MdxTextExpression | PhrasingContent
|
||||
```
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports the additional types [`MdxFlowExpression`][api-mdx-flow-expression],
|
||||
[`MdxFlowExpressionHast`][api-mdx-flow-expression-hast],
|
||||
[`MdxTextExpression`][api-mdx-text-expression], and
|
||||
[`MdxTextExpressionHast`][api-mdx-text-expression-hast].
|
||||
|
||||
It also registers the node types with `@types/mdast` and `@types/hast`.
|
||||
If you’re 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-expression')}
|
||||
*/
|
||||
|
||||
import {visit} from 'unist-util-visit'
|
||||
|
||||
/** @type {import('mdast').Root} */
|
||||
const tree = getMdastNodeSomeHow()
|
||||
|
||||
visit(tree, (node) => {
|
||||
// `node` can now be an expression node.
|
||||
})
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
* [`remarkjs/remark-mdx`][remark-mdx]
|
||||
— remark plugin to support MDX
|
||||
* [`syntax-tree/mdast-util-mdx`][mdast-util-mdx]
|
||||
— mdast utility to support MDX
|
||||
* [`micromark/micromark-extension-mdx-expression`][extension]
|
||||
— micromark extension to parse MDX expressions
|
||||
|
||||
## 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]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/mdast-util-mdx-expression/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/mdast-util-mdx-expression/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-mdx-expression.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-mdx-expression
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-mdx-expression.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/mdast-util-mdx-expression
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-mdx-expression.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=mdast-util-mdx-expression
|
||||
|
||||
[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
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
|
||||
[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
|
||||
|
||||
[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
|
||||
|
||||
[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
|
||||
|
||||
[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx
|
||||
|
||||
[extension]: https://github.com/micromark/micromark-extension-mdx-expression
|
||||
|
||||
[syntax]: https://github.com/micromark/micromark-extension-mdx-expression#syntax
|
||||
|
||||
[program]: https://github.com/estree/estree/blob/master/es2015.md#programs
|
||||
|
||||
[dfn-literal]: https://github.com/syntax-tree/mdast#literal
|
||||
|
||||
[remark-mdx]: https://mdxjs.com/packages/remark-mdx/
|
||||
|
||||
[mdx]: https://mdxjs.com
|
||||
|
||||
[api-mdx-expression-from-markdown]: #mdxexpressionfrommarkdown
|
||||
|
||||
[api-mdx-expression-to-markdown]: #mdxexpressiontomarkdown
|
||||
|
||||
[api-mdx-flow-expression]: #mdxflowexpression
|
||||
|
||||
[api-mdx-text-expression]: #mdxtextexpression
|
||||
|
||||
[api-mdx-flow-expression-hast]: #mdxflowexpressionhast
|
||||
|
||||
[api-mdx-text-expression-hast]: #mdxtextexpressionhast
|
||||
|
||||
[dfn-flow-content]: #flowcontent-mdx-expression
|
||||
|
||||
[dfn-phrasing-content]: #phrasingcontent-mdx-expression
|
||||
Loading…
Add table
Add a link
Reference in a new issue