@unifast/shiki

Shiki-based syntax highlighting plugin for unifast with HAST transforms

Overview

@unifast/shiki provides syntax highlighting powered by Shiki, supporting 200+ languages and a wide variety of themes. Unlike the built-in highlight plugin, Shiki runs as a HAST transform in JavaScript, replacing <pre><code> blocks with richly styled output.

The plugin automatically disables the built-in Rust highlighter to avoid double-processing.

Installation

Type Definitions

ShikiTransformerOptions

PropertyTypeDefaultDescription
themesBundledTheme[]["github-dark"]Shiki themes to load
defaultThemeBundledThemeFirst theme in themesDefault theme for rendering
langsBundledLanguage[][]Languages to load. Only loaded languages will be highlighted.

BundledTheme and BundledLanguage are types from the shiki package.

ShikiTransformer

PropertyTypeDescription
transform(hast: HastRoot) => HastRootApply Shiki highlighting to all <pre><code class="language-*"> blocks

Exports Summary

ExportKindDescription
createShikiPluginfunctionCreate a Shiki UnifastPlugin (async)
createShikiTransformerfunctionCreate a standalone Shiki transformer (async)
ShikiTransformerOptionstypeShiki configuration options
ShikiTransformertypeTransformer interface
hastToHtmlfunctionHAST-to-HTML serializer (re-exported)
HastNode, HastRoot, etc.typesHAST node types (re-exported)