快速入門

在一分鐘之內安裝 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

後續閱讀