{
  "url": "https://unifast.dev/vi/docs/packages/core/overview/",
  "locale": "vi",
  "title": "@unifast/core",
  "description": "Các định nghĩa kiểu TypeScript, tiện ích HAST và lớp lỗi được dùng chung giữa các gói runtime của unifast",
  "section": "packages",
  "body": "## Tổng quan\n\n`@unifast/core` cung cấp các định nghĩa kiểu TypeScript dùng chung cho tùy chọn biên dịch, kết quả, các nút HAST (HTML Abstract Syntax Tree), interface plugin và các lớp lỗi. Nó là dependency của các gói runtime như `@unifast/node` — bạn thường **không** cần cài đặt trực tiếp.\n\nĐể sử dụng trình biên dịch và các plugin tích hợp sẵn, hãy dùng [`@unifast/node`](/docs/packages/node/overview).\n\n## Cài đặt\n\n## Định nghĩa kiểu\n\n### CompileOptions\n\nCấu hình cho hàm `compile()`.\n\n| Thuộc tính | Kiểu | Mặc định | Mô tả |\n|----------|------|---------|-------------|\n| `inputKind` | `\"md\" \\| \"mdx\"` | `\"md\"` | Định dạng đầu vào |\n| `outputKind` | `\"html\" \\| \"hast\" \\| \"mdast\" \\| \"mdxJs\"` | `\"html\"` | Định dạng đầu ra |\n| `gfm` | `object` | - | Các thiết lập GitHub Flavored Markdown |\n| `gfm.tables` | `boolean` | - | Bật bảng GFM |\n| `gfm.taskList` | `boolean` | - | Bật checkbox danh sách tác vụ |\n| `gfm.strikethrough` | `boolean` | - | Bật `~~strikethrough~~` |\n| `gfm.footnotes` | `boolean` | - | Bật chú thích cuối |\n| `gfm.autolink` | `boolean` | - | Bật auto-link cho URL |\n| `frontmatter` | `object` | - | Các thiết lập parsing frontmatter |\n| `frontmatter.yaml` | `boolean` | - | Parse frontmatter YAML |\n| `frontmatter.toml` | `boolean` | - | Parse frontmatter TOML |\n| `frontmatter.json` | `boolean` | - | Parse frontmatter JSON |\n| `rawHtml` | `\"disallow\" \\| \"allowDangerous\" \\| \"parseAndSanitize\"` | - | Cách xử lý HTML thô trong source |\n| `sanitize` | `object` | - | Thiết lập sanitization HTML |\n| `sanitize.enabled` | `boolean` | - | Bật sanitization |\n| `sanitize.schema` | `SanitizeSchema` | - | Quy tắc sanitization tùy chỉnh |\n| `highlight` | `object` | - | Thiết lập syntax highlighting |\n| `highlight.enabled` | `boolean` | - | Bật syntax highlighting |\n| `highlight.engine` | `\"none\" \\| \"syntect\" \\| \"treeSitter\"` | - | Engine highlight |\n| `slug` | `object` | - | Thiết lập sinh slug cho tiêu đề |\n| `slug.mode` | `\"github\" \\| \"unicode\"` | - | Thuật toán sinh slug |\n| `toc` | `object` | - | Thiết lập mục lục |\n| `toc.enabled` | `boolean` | - | Bật trích xuất TOC |\n| `toc.maxDepth` | `number` | - | Độ sâu tiêu đề tối đa được bao gồm |\n| `diagnostics` | `object` | - | Thiết lập đầu ra diagnostic |\n| `diagnostics.format` | `\"compact\" \\| \"verbose\"` | - | Định dạng diagnostic |\n| `cache` | `object` | - | Thiết lập cache |\n| `cache.enabled` | `boolean` | - | Bật cache kết quả |\n| `cache.dir` | `string` | - | Đường dẫn thư mục cache |\n| `plugins` | `UnifastPlugin[]` | `[]` | Mảng plugin được áp dụng |\n\n### CompileResult\n\nGiá trị trả về của hàm `compile()`.\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `output` | `string \\| object` | Đầu ra đã biên dịch (chuỗi HTML, HAST JSON, hoặc MDAST JSON tùy thuộc vào `outputKind`) |\n| `frontmatter` | `Record<string, unknown>` | Metadata frontmatter đã được parse |\n| `diagnostics` | `Diagnostic[]` | Mảng cảnh báo và lỗi |\n| `stats` | `{ parseMs, transformMs, emitMs }` | Thống kê thời gian theo mili-giây |\n| `toc` | `TocEntry[]` | Các mục của bảng mục lục đã được trích xuất |\n\n### Diagnostic\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `level` | `\"error\" \\| \"warn\"` | Mức độ nghiêm trọng |\n| `message` | `string` | Thông điệp dễ đọc cho con người |\n| `start` | `number \\| undefined` | Offset byte bắt đầu trong source |\n| `end` | `number \\| undefined` | Offset byte kết thúc trong source |\n| `line` | `number \\| undefined` | Số dòng (bắt đầu từ 1) |\n| `column` | `number \\| undefined` | Số cột (bắt đầu từ 1) |\n\n### TocEntry\n\nMột tiêu đề được trích xuất cho bảng mục lục.\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `depth` | `number` | Cấp độ tiêu đề (1-6) |\n| `text` | `string` | Nội dung văn bản thuần của tiêu đề |\n| `slug` | `string` | Slug đã sinh để dùng làm anchor link |\n\n### SanitizeSchema\n\nCác quy tắc sanitization tùy chỉnh.\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `allowedTags` | `string[]` | Các thẻ HTML được phép |\n| `allowedAttributes` | `Record<string, string[]>` | Các thuộc tính được phép cho từng thẻ |\n| `allowedProtocols` | `Record<string, string[]>` | Các protocol URL được phép cho từng thuộc tính |\n\n### UnifastPlugin\n\nInterface plugin để mở rộng unifast.\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `name` | `string` | Tên plugin duy nhất |\n| `options?` | `Partial<CompileOptions>` | Các tùy chọn sẽ được gộp vào tùy chọn biên dịch |\n| `hastTransform?` | `(hast: HastRoot) => HastRoot` | Biến đổi cây HAST sau khi biên dịch |\n\n### Các loại nút HAST\n\n| Kiểu | Trường `type` | Thuộc tính | Mô tả |\n|------|-------------|------------|-------------|\n| `HastRoot` | `\"root\"` | `children: HastNode[]` | Nút gốc của cây |\n| `HastElement` | `\"element\"` | `tagName`, `properties`, `children` | Một phần tử HTML |\n| `HastText` | `\"text\"` | `value: string` | Một nút văn bản |\n| `HastRaw` | `\"raw\"` | `value: string` | Đi qua HTML thô |\n| `HastComment` | `\"comment\"` | `value: string` | Một comment HTML |\n| `HastDoctype` | `\"doctype\"` | - | Một nút `<!DOCTYPE html>` |\n\n`HastNode` là kiểu union: `HastRoot | HastElement | HastText | HastRaw | HastComment | HastDoctype`\n\n## Các lớp lỗi\n\n| Lớp | Kế thừa | Thuộc tính | Mô tả |\n|-------|---------|------------|-------------|\n| `UnifastError` | `Error` | `code?: string`, `span?: { start, end }` | Lớp lỗi cơ sở cho tất cả lỗi của unifast |\n| `ParseError` | `UnifastError` | `code: \"PARSE_ERROR\"` | Được ném ra khi không thể parse đầu vào Markdown/MDX |\n| `CompileError` | `UnifastError` | `code: \"COMPILE_ERROR\"` | Được ném ra khi biên dịch thất bại sau khi parse |\n\n```ts\n\ntry {\n  // ... compile something\n} catch (err) {\n  if (err instanceof ParseError) {\n    console.error(`Parse error at ${err.span?.start}: ${err.message}`);\n  } else if (err instanceof CompileError) {\n    console.error(`Compile error: ${err.message}`);\n  }\n}\n```\n\n## Tổng hợp các export\n\n| Export | Loại | Mô tả |\n|--------|------|-------------|\n| `CompileOptions` | type | Cấu hình biên dịch |\n| `CompileResult` | type | Kết quả biên dịch |\n| `TocEntry` | type | Mục của bảng mục lục |\n| `SanitizeSchema` | type | Quy tắc sanitization |\n| `UnifastPlugin` | type | Interface plugin |\n| `HastNode` | type | Union của tất cả các loại nút HAST |\n| `HastRoot` | type | Nút gốc HAST |\n| `HastElement` | type | Nút phần tử HAST |\n| `HastText` | type | Nút văn bản HAST |\n| `HastRaw` | type | Nút HTML thô HAST |\n| `HastComment` | type | Nút comment HAST |\n| `HastDoctype` | type | Nút doctype HAST |\n| `hastToHtml` | function | Bộ tuần tự hóa HAST-to-HTML |\n| `escapeHtml` | function | Escape các ký tự đặc biệt của HTML (`&`, `<`, `>`, `\"`) |\n| `extractLang` | function | Trích xuất định danh ngôn ngữ từ phần tử HAST `<code>` |\n| `extractText` | function | Trích xuất nội dung văn bản thuần từ một nút HAST |\n| `findCodeChild` | function | Tìm phần tử con `<code>` bên trong phần tử `<pre>` |\n| `visitHast` | function | Tiện ích visitor pattern để duyệt cây HAST |\n| `UnifastError` | class | Lớp lỗi cơ sở |\n| `ParseError` | class | Lớp lỗi parse |\n| `CompileError` | class | Lớp lỗi biên dịch |",
  "alternates": [
    {
      "locale": "en",
      "url": "https://unifast.dev/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/docs/packages/core/overview.json"
    },
    {
      "locale": "ja",
      "url": "https://unifast.dev/ja/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/ja/docs/packages/core/overview.json"
    },
    {
      "locale": "zh-CN",
      "url": "https://unifast.dev/zh-CN/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/zh-CN/docs/packages/core/overview.json"
    },
    {
      "locale": "zh-TW",
      "url": "https://unifast.dev/zh-TW/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/zh-TW/docs/packages/core/overview.json"
    },
    {
      "locale": "ko",
      "url": "https://unifast.dev/ko/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/ko/docs/packages/core/overview.json"
    },
    {
      "locale": "fr",
      "url": "https://unifast.dev/fr/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/fr/docs/packages/core/overview.json"
    },
    {
      "locale": "it",
      "url": "https://unifast.dev/it/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/it/docs/packages/core/overview.json"
    },
    {
      "locale": "es",
      "url": "https://unifast.dev/es/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/es/docs/packages/core/overview.json"
    },
    {
      "locale": "pt-BR",
      "url": "https://unifast.dev/pt-BR/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/pt-BR/docs/packages/core/overview.json"
    },
    {
      "locale": "de",
      "url": "https://unifast.dev/de/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/de/docs/packages/core/overview.json"
    },
    {
      "locale": "ru",
      "url": "https://unifast.dev/ru/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/ru/docs/packages/core/overview.json"
    },
    {
      "locale": "hi",
      "url": "https://unifast.dev/hi/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/hi/docs/packages/core/overview.json"
    },
    {
      "locale": "id",
      "url": "https://unifast.dev/id/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/id/docs/packages/core/overview.json"
    },
    {
      "locale": "tr",
      "url": "https://unifast.dev/tr/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/tr/docs/packages/core/overview.json"
    },
    {
      "locale": "vi",
      "url": "https://unifast.dev/vi/docs/packages/core/overview/",
      "api": "https://unifast.dev//api/vi/docs/packages/core/overview.json"
    }
  ]
}
