@astropub/md

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

Render any Markdown content in Astro

原始使用文档

Astro Markdown

Astro Markdown lets you render any Markdown content in Astro, optionally integrating with any existing configuration.

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!`)
}

Usage

Add Astro Markdown to your project.

npm install @astropub/md

Use Astro Markdown in your project.

---
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>

Optionally, integrate Astro Markdown with your existing Astro configuration.

// 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'
  }
})

Now markdown configuration is automatically applied to <Markdown> components and markdown() functions.

Use markdown.inline() or <Markdown.Inline> to handle short strings of text without the surrounding paragraph.

---
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_.`
)}

Enjoy!


Want to learn more? Read the Astro documentation or jump into the 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 是什么?

Render any Markdown content in Astro

如何安装 @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 和提交记录判断。