Bắt đầu nhanh

Cài đặt unifast và biên dịch tài liệu Markdown đầu tiên của bạn trong chưa đầy một phút.

Cài đặt unifast và biên dịch tài liệu Markdown đầu tiên của bạn trong chưa đầy một phút.

Cài đặt

Cách dùng cơ bản

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>

Chỉ vậy thôi. Một lệnh import, một lời gọi hàm, và bạn đã có HTML.

Thêm plugin

Plugin mở rộng trình biên dịch với các tính năng bổ sung. Phần lớn plugin được đóng gói sẵn trong @unifast/node và cấu hình các pass tích hợp sẵn.

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

Thêm syntax highlighting

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

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

Tiếp theo là gì