Files
n8n_Demo/web_frontend/food-order-demo/node_modules/mdast-util-mdxjs-esm
Yep_Q c3eb7125cc feat: 创建食品订单班演示系统基础框架
详细说明:
- 基于文旅订单班框架复制创建food-order-demo项目
- 修改端口配置为4174避免冲突
- 更新LandingPage为青莳轻食主题(绿色健康风格)
- 重新定义7个食品行业专业Agent:
  * 市场研究专家:轻食市场分析、客群画像
  * 营养配方师:营养成分配比、低卡高蛋白设计
  * 供应链管理专家:有机食材供应、溯源体系
  * 品牌策划师:品牌定位、店铺空间布局
  * 财务分析师:投资预算、ROI分析
  * 运营管理专家:运营流程、品控标准
  * 食品创业导师:中央协调、方案整合
- 创建专用启动脚本start.sh
- 验证系统可正常运行在端口4174
- 实现代码复用率90%,符合预期目标

影响文件: web_frontend/food-order-demo/
技术栈: React 18 + TypeScript + Tailwind CSS + Zustand
2025-09-28 10:32:44 +08:00
..

mdast-util-mdxjs-esm

Build Coverage Downloads Size Sponsors Backers Chat

mdast extensions to parse and serialize MDX ESM (import/exports).

Contents

What is this?

This package contains two extensions that add support for MDX ESM syntax in markdown to mdast. These extensions plug into mdast-util-from-markdown (to support parsing ESM in markdown into a syntax tree) and mdast-util-to-markdown (to support serializing ESM 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-mdxjs-esm.

When you are working with syntax trees and want all of MDX, use mdast-util-mdx instead.

All these packages are used in remark-mdx, which focusses on making it easier to transform content by abstracting these internals away.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install mdast-util-mdxjs-esm

In Deno with esm.sh:

import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2'

In browsers with esm.sh:

<script type="module">
  import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2?bundle'
</script>

Use

Say our document example.mdx contains:

import a from 'b'
export const c = ''

d

…and our module example.js looks as follows:

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 {mdxjsEsm} from 'micromark-extension-mdxjs-esm'
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'mdast-util-mdxjs-esm'

const doc = await fs.readFile('example.mdx')

const tree = fromMarkdown(doc, {
  extensions: [mdxjsEsm({acorn, addResult: true})],
  mdastExtensions: [mdxjsEsmFromMarkdown()]
})

console.log(tree)

const out = toMarkdown(tree, {extensions: [mdxjsEsmToMarkdown()]})

console.log(out)

…now running node example.js yields (positional info removed for brevity):

{
  type: 'root',
  children: [
    {
      type: 'mdxjsEsm',
      value: "import a from 'b'\nexport const c = ''",
      data: {
        estree: {
          type: 'Program',
          body: [
            {
              type: 'ImportDeclaration',
              specifiers: [
                {
                  type: 'ImportDefaultSpecifier',
                  local: {type: 'Identifier', name: 'a'}
                }
              ],
              source: {type: 'Literal', value: 'b', raw: "'b'"}
            },
            {
              type: 'ExportNamedDeclaration',
              declaration: {
                type: 'VariableDeclaration',
                declarations: [
                  {
                    type: 'VariableDeclarator',
                    id: {type: 'Identifier', name: 'c'},
                    init: {type: 'Literal', value: '', raw: "''"}
                  }
                ],
                kind: 'const'
              },
              specifiers: [],
              source: null
            }
          ],
          sourceType: 'module'
        }
      }
    },
    {type: 'paragraph', children: [{type: 'text', value: 'd'}]}
  ]
}
import a from 'b'
export const c = ''

d

API

This package exports the identifiers mdxjsEsmFromMarkdown and mdxjsEsmToMarkdown. There is no default export.

mdxjsEsmFromMarkdown()

Create an extension for mdast-util-from-markdown to enable MDX.js ESM in markdown.

When using the micromark syntax extension with addResult, nodes will have a data.estree field set to an ESTree Program node.

Returns

Extension for mdast-util-from-markdown to enable MDX.js ESM (FromMarkdownExtension).

mdxjsEsmToMarkdown()

Create an extension for mdast-util-to-markdown to enable MDX.js ESM in markdown.

Returns

Extension for mdast-util-to-markdown to enable MDX.js ESM (ToMarkdownExtension).

MdxjsEsm

MDX ESM (import/export) node (TypeScript type).

Type
import type {Program} from 'estree-jsx'
import type {Data, Literal} from 'mdast'

interface MdxjsEsm extends Literal {
  type: 'mdxjsEsm'
  data?: MdxjsEsmData | undefined
}

export interface MdxjsEsmData extends Data {
  estree?: Program | null | undefined
}

MdxjsEsmHast

Same as MdxjsEsm, but registered with @types/hast (TypeScript type).

Type
import type {Program} from 'estree-jsx'
import type {Data, Literal} from 'hast'

interface MdxjsEsmHast extends Literal {
  type: 'mdxjsEsm'
  data?: MdxjsEsmHastData | undefined
}

export interface MdxjsEsmHastData extends Data {
  estree?: Program | null | undefined
}

HTML

MDX ESM has no representation in HTML. Though, when you are dealing with MDX, you will likely go through hast. You can enable passing MDX ESM through to hast by configuring mdast-util-to-hast with passThrough: ['mdxjsEsm'].

Syntax

See Syntax in micromark-extension-mdxjs-esm.

Syntax tree

The following interfaces are added to mdast by this utility.

Nodes

MdxjsEsm

interface MdxjsEsm <: Literal {
  type: 'mdxjsEsm'
}

MdxjsEsm (Literal) represents ESM import/exports embedded in MDX. It can be used where flow content is expected. Its content is represented by its value field.

For example, the following Markdown:

import a from 'b'

Yields:

{
  type: 'mdxjsEsm',
  value: 'import a from \'b\''
}

Content model

FlowContent (MDX.js ESM)

type FlowContentMdxjsEsm = MdxjsEsm | FlowContent

Note that when ESM is present, it can only exist as top-level content: if it has a parent, that parent must be Root.

Types

This package is fully typed with TypeScript. It exports the additional types MdxjsEsm and MdxjsEsmHast.

It also registers the node type 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.

/**
 * @typedef {import('mdast-util-mdxjs-esm')}
 */

import {visit} from 'unist-util-visit'

/** @type {import('mdast').Root} */
const tree = getMdastNodeSomeHow()

visit(tree, function (node) {
  // `node` can now be an ESM node.
})

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-mdxjs-esm@^2, compatible with Node.js 16.

This utility works with mdast-util-from-markdown version 2+ and mdast-util-to-markdown version 2+.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer