@astrojs/micromark-extension-mdx-jsx

中文文档
1.0.3发布于 2022/06/08MITTypeScriptES Module近 30 天下载 2.8万

Less strict version of micromark-extension-mdx-jsx.

原始使用文档
文档目录4 节
  1. Syntax differences
  2. Colons ( : ) preceded by whitespace start attribute names i…
  3. Attribute names can start with @
  4. Attribute names can contain dots ( . )

@astrojs/micromark-extension-mdx-jsx

This fork is based on micromark/micromark-extension-mdx-jsx by the original author Titus Wormer.

The purpose of this fork is to provide extended MDX/JSX syntax support for the Astro website build tool. If you're not using Astro, you should probably use the original extension instead of this fork.

Syntax differences

Colons (:) preceded by whitespace start attribute names instead of local names

The original code always treated colons inside JSX tags as a separator between a primary name and a local name, even if there was whitespace before the colon. Our forked version starts an attribute name instead of a local name if there is whitespace before the colon.

This leads to the following changes:

  • The syntax <input :placeholder="..."> is now treated as an input element with an attribute named :placeholder.
    • The original code treated this like <input:placeholder="...">, resulting in an element named input:placeholder (with placeholder being the local name of the element), and a syntax error due to the following unexpected value assignment ="...".
  • The syntax <input disabled :placeholder="..."> is now treated as an input element with two attributes named disabled and :placeholder.
    • The original code treated this like <input disabled:placeholder="...">, resulting in an input element with only one attribute named disabled:placeholder.

As a result, these AlpineJS examples now work as expected:

<input type="text" :placeholder="placeholder">
<input type="text" disabled :placeholder="placeholder">
<div :class="open ? '' : 'hidden'">Test</div>
<div :style="true && { color: 'red' }">Test</div>

Attribute names can start with @

The original code did not allow attribute names to start with @. Our forked version allows this.

As a result, these examples using the AlpineJS shorthand syntax for x-on: now work as expected:

<button @click="handleClick">Test</button>

Attribute names can contain dots (.)

The original code did not allow attribute names to contain dots. Our forked version allows this.

As a result, in combination with our change that allows @ to start attribute names, these AlpineJS examples now work as expected:

<button @click.once="console.log('I will only log once')">Test</button>
<input @input.debounce="fetchResults">
<input @input.debounce.500ms="fetchResults">
<div @keyup.escape.window="...">Test</div>

版本与发布记录

@astrojs/micromark-extension-mdx-jsx 共发布 1 个版本,首次发布于 2022/06/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.3latest2022/06/084 年前

关于 @astrojs/micromark-extension-mdx-jsx 的常见问题

@astrojs/micromark-extension-mdx-jsx 是什么?

Less strict version of micromark-extension-mdx-jsx.

如何安装 @astrojs/micromark-extension-mdx-jsx?

在项目目录运行 npm install @astrojs/micromark-extension-mdx-jsx,或使用 pnpm add / yarn add / bun add。

@astrojs/micromark-extension-mdx-jsx 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@astrojs/micromark-extension-mdx-jsx 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@astrojs/micromark-extension-mdx-jsx 可以商用吗?

@astrojs/micromark-extension-mdx-jsx 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@astrojs/micromark-extension-mdx-jsx 的下载量有多少?

根据 npm 官方下载统计,@astrojs/micromark-extension-mdx-jsx 在 2026/10/07 – 2026/11/05 这 30 天内被下载 28,368 次,日均约 946 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@astrojs/micromark-extension-mdx-jsx 还在维护吗?

最新版本 1.0.3 发布于 2022/06/08(4 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/06/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。