@astropub/md

中文文档
1.0.0发布于 2024/07/29CC0-1.0TypeScriptES Module零依赖近 30 天下载 1.8万

在 Astro 中渲染任何 Markdown 内容

中文使用文档

天体标记

天体标记 让您将任何 Markdown 内容输入 天体,可选择与任何现有配置相融合.

NPM Version NPM Downloads Open in StackBlitz

---
import { Markdown } from '@astropub/md'
---
<Markdown of={`# Hi, there!` /* Renders `<h1>Hi, there!</h1>` */} />
---
import { markdown } from '@astropub/md'
---
{
  /* Renders `<h1>Hi, there!</h1>` */
  await markdown(`# Hi, there!`)
}

使用量

添加 天体标记 你的项目.

npm install @astropub/md

使用 天体标记 在你的项目.

---
import { markdown } from '@astropub/md'
---
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Astro</title>
  </head>
  <body>
    {await markdown(
`# Hi, there!

Welcome to my _website_.`
    )}
  </body>
</html>

选择性地整合 天体标记 使用您的 Astro 配置 .

// astro.config.js
import { defineConfig } from 'astro/config'
import markdownIntegration from '@astropub/md'

export default defineConfig({
  integrations: [
    markdownIntegration(),
  ],
  markdown: {
    remarkPlugins: [],
    rehypePlugins: [],
    // syntaxHighlight: 'shiki'
    // syntaxHighlight: 'prism'
  }
})

现在 markdown 配置自动应用到 <Markdown> 组件和组件 markdown() 函数.

使用 markdown.inline() 或者说 <Markdown.Inline> 用于处理文本的短串,而不包含相邻段落.

---
import { Markdown } from '@astropub/md'
---
<Markdown.Inline of={
  /* Renders `Welcome to my <em>website</em>.` */
  `Welcome to my _website_.`
} />
---
import { markdown } from '@astropub/md'
---
{await markdown.inline(
  /* Renders `Welcome to my <em>website</em>.` */
  `Welcome to my _website_.`
)}

慢慢来!


想多学点吗? 读取 Astro 文档 或跳入 Astro Discord (Astro Discord) 时尚主题 :。 。 。 .

版本与发布记录

@astropub/md 共发布 10 个版本,首次发布于 2022/08/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2024/07/292 年前
0.4.02024/01/122 年前
0.3.02023/11/043 年前
0.2.02023/03/143 年前
0.1.52023/02/103 年前
0.1.42022/12/163 年前

关于 @astropub/md 的常见问题

@astropub/md 是什么?

在 Astro 中渲染任何 Markdown 内容

如何安装 @astropub/md?

在项目目录运行 npm install @astropub/md,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@astrojs/markdown-remark(^5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@astropub/md 支持 TypeScript 吗?

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

@astropub/md 支持 ESM 还是 CommonJS?

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

@astropub/md 可以商用吗?

@astropub/md 使用 CC0-1.0 许可。作者放弃著作权,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@astropub/md 的下载量有多少?

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

@astropub/md 还在维护吗?

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