{
  "url": "https://unifast.dev/docs/packages/core/overview/",
  "locale": "en",
  "title": "@unifast/core",
  "description": "TypeScript type definitions, HAST utilities, and error classes shared across unifast runtime packages",
  "section": "packages",
  "body": "## Overview\n\n`@unifast/core` provides shared TypeScript type definitions for compile options, results, HAST (HTML Abstract Syntax Tree) nodes, the plugin interface, and error classes. It is a dependency of runtime packages like `@unifast/node` — you typically do **not** need to install it directly.\n\nFor the compiler and built-in plugins, use [`@unifast/node`](/docs/packages/node/overview).\n\n## Installation\n\n## Type Definitions\n\n### CompileOptions\n\nConfiguration for the `compile()` function.\n\n| Property | Type | Default | Description |\n|----------|------|---------|-------------|\n| `inputKind` | `\"md\" \\| \"mdx\"` | `\"md\"` | Input format |\n| `outputKind` | `\"html\" \\| \"hast\" \\| \"mdast\" \\| \"mdxJs\"` | `\"html\"` | Output format |\n| `gfm` | `object` | - | GitHub Flavored Markdown settings |\n| `gfm.tables` | `boolean` | - | Enable GFM tables |\n| `gfm.taskList` | `boolean` | - | Enable task list checkboxes |\n| `gfm.strikethrough` | `boolean` | - | Enable `~~strikethrough~~` |\n| `gfm.footnotes` | `boolean` | - | Enable footnotes |\n| `gfm.autolink` | `boolean` | - | Enable URL auto-linking |\n| `frontmatter` | `object` | - | Frontmatter parsing settings |\n| `frontmatter.yaml` | `boolean` | - | Parse YAML frontmatter |\n| `frontmatter.toml` | `boolean` | - | Parse TOML frontmatter |\n| `frontmatter.json` | `boolean` | - | Parse JSON frontmatter |\n| `rawHtml` | `\"disallow\" \\| \"allowDangerous\" \\| \"parseAndSanitize\"` | - | How to handle raw HTML in source |\n| `sanitize` | `object` | - | HTML sanitization settings |\n| `sanitize.enabled` | `boolean` | - | Enable sanitization |\n| `sanitize.schema` | `SanitizeSchema` | - | Custom sanitization rules |\n| `highlight` | `object` | - | Syntax highlighting settings |\n| `highlight.enabled` | `boolean` | - | Enable syntax highlighting |\n| `highlight.engine` | `\"none\" \\| \"syntect\" \\| \"treeSitter\"` | - | Highlighting engine |\n| `slug` | `object` | - | Heading slug generation settings |\n| `slug.mode` | `\"github\" \\| \"unicode\"` | - | Slug generation algorithm |\n| `toc` | `object` | - | Table of contents settings |\n| `toc.enabled` | `boolean` | - | Enable TOC extraction |\n| `toc.maxDepth` | `number` | - | Maximum heading depth to include |\n| `diagnostics` | `object` | - | Diagnostic output settings |\n| `diagnostics.format` | `\"compact\" \\| \"verbose\"` | - | Diagnostic format |\n| `cache` | `object` | - | Caching settings |\n| `cache.enabled` | `boolean` | - | Enable result caching |\n| `cache.dir` | `string` | - | Cache directory path |\n| `plugins` | `UnifastPlugin[]` | `[]` | Array of plugins to apply |\n\n### CompileResult\n\nReturned by the `compile()` function.\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `output` | `string \\| object` | Compiled output (HTML string, HAST JSON, or MDAST JSON depending on `outputKind`) |\n| `frontmatter` | `Record<string, unknown>` | Parsed frontmatter metadata |\n| `diagnostics` | `Diagnostic[]` | Array of warnings and errors |\n| `stats` | `{ parseMs, transformMs, emitMs }` | Timing breakdown in milliseconds |\n| `toc` | `TocEntry[]` | Extracted table of contents entries |\n\n### Diagnostic\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `level` | `\"error\" \\| \"warn\"` | Severity level |\n| `message` | `string` | Human-readable message |\n| `start` | `number \\| undefined` | Start byte offset in source |\n| `end` | `number \\| undefined` | End byte offset in source |\n| `line` | `number \\| undefined` | Line number (1-based) |\n| `column` | `number \\| undefined` | Column number (1-based) |\n\n### TocEntry\n\nA single heading extracted for the table of contents.\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `depth` | `number` | Heading level (1-6) |\n| `text` | `string` | Plain text content of the heading |\n| `slug` | `string` | Generated slug for anchor linking |\n\n### SanitizeSchema\n\nCustom sanitization rules.\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `allowedTags` | `string[]` | HTML tags to allow |\n| `allowedAttributes` | `Record<string, string[]>` | Allowed attributes per tag |\n| `allowedProtocols` | `Record<string, string[]>` | Allowed URL protocols per attribute |\n\n### UnifastPlugin\n\nThe plugin interface for extending unifast.\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `name` | `string` | Unique plugin name |\n| `options?` | `Partial<CompileOptions>` | Options to merge into compile options |\n| `hastTransform?` | `(hast: HastRoot) => HastRoot` | Transform the HAST tree after compilation |\n\n### HAST Node Types\n\n| Type | `type` field | Properties | Description |\n|------|-------------|------------|-------------|\n| `HastRoot` | `\"root\"` | `children: HastNode[]` | Root node of the tree |\n| `HastElement` | `\"element\"` | `tagName`, `properties`, `children` | An HTML element |\n| `HastText` | `\"text\"` | `value: string` | A text node |\n| `HastRaw` | `\"raw\"` | `value: string` | Raw HTML passthrough |\n| `HastComment` | `\"comment\"` | `value: string` | An HTML comment |\n| `HastDoctype` | `\"doctype\"` | - | A `<!DOCTYPE html>` node |\n\n`HastNode` is the union type: `HastRoot | HastElement | HastText | HastRaw | HastComment | HastDoctype`\n\n## Error Classes\n\n| Class | Extends | Properties | Description |\n|-------|---------|------------|-------------|\n| `UnifastError` | `Error` | `code?: string`, `span?: { start, end }` | Base error class for all unifast errors |\n| `ParseError` | `UnifastError` | `code: \"PARSE_ERROR\"` | Thrown when Markdown/MDX input cannot be parsed |\n| `CompileError` | `UnifastError` | `code: \"COMPILE_ERROR\"` | Thrown when compilation fails after parsing |\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## Exports Summary\n\n| Export | Kind | Description |\n|--------|------|-------------|\n| `CompileOptions` | type | Compilation configuration |\n| `CompileResult` | type | Compilation result |\n| `TocEntry` | type | Table of contents entry |\n| `SanitizeSchema` | type | Sanitization rules |\n| `UnifastPlugin` | type | Plugin interface |\n| `HastNode` | type | Union of all HAST node types |\n| `HastRoot` | type | HAST root node |\n| `HastElement` | type | HAST element node |\n| `HastText` | type | HAST text node |\n| `HastRaw` | type | HAST raw HTML node |\n| `HastComment` | type | HAST comment node |\n| `HastDoctype` | type | HAST doctype node |\n| `hastToHtml` | function | HAST-to-HTML serializer |\n| `escapeHtml` | function | Escape HTML special characters (`&`, `<`, `>`, `\"`) |\n| `extractLang` | function | Extract language identifier from a HAST `<code>` element |\n| `extractText` | function | Extract plain text content from a HAST node |\n| `findCodeChild` | function | Find the `<code>` child element inside a `<pre>` element |\n| `visitHast` | function | Visitor pattern utility for walking HAST trees |\n| `UnifastError` | class | Base error class |\n| `ParseError` | class | Parse error class |\n| `CompileError` | class | Compile error class |",
  "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"
    }
  ]
}
