快速开始

在一分钟内安装 unifast,并完成你的第一个 Markdown 文档编译。

在一分钟内安装 unifast,并完成你的第一个 Markdown 文档编译。

安装

基本用法

import { compile } from "@unifast/node";

const result = compile("# Hello, unifast!\n\nThis is **Markdown**.");

console.log(result.html);
// <h1>Hello, unifast!</h1>
// <p>This is <strong>Markdown</strong>.</p>

就这么简单:一条 import、一次函数调用,便可得到 HTML 输出。

添加插件

插件为编译器提供额外能力。大多数插件已包含在 @unifast/node 中,用于配置各项内置处理阶段。

import { compile, frontmatter, gfm } from "@unifast/node";

const source = `---
title: My Post
date: 2025-01-15
---

# My Post

A table:

| Feature | Status |
|---------|--------|
| GFM     | Yes    |

- [x] Task complete
- [ ] Task pending
`;

const result = compile(source, {
  plugins: [frontmatter(), gfm()],
});

console.log(result.frontmatter);
// { title: "My Post", date: "2025-01-15" }

console.log(result.html);
// Rendered HTML with GFM table and task list

添加语法高亮

import { compile, syntect } from "@unifast/node";

const result = compile(
  '```js\nconsole.log("highlighted");\n```',
  { plugins: [syntect()] }
);
// Code block with syntax highlighting classes

下一步

  • 核心概念 —— 了解编译管线与整体架构。

  • 语法高亮 —— 详细配置代码块的高亮方式。

  • compile() —— 完整的 compile 函数 API 参考。