Shiki Syntax Highlighter
repository·main·Indexed 12 days ago
https://github.com/shikijs/shikiA powerful syntax highlighter based on TextMate grammars for web environments. Version 4.4.3 features a modular ecosystem including @shikijs/core for minimal installations, regex engines via @shikijs/engine-oniguruma and @shikijs/engine-javascript, and integrations for Monaco Editor, markdown-it, and rehype. It supports advanced features like VSCode-style bracket highlighting, streaming colorization for LLMs, and TypeScript Twoslash annotations.
What's inside Shiki
Introduction to Shiki
mainShiki (式) is a syntax highlighter based on TextMate grammars and themes, the same engine used by VS Code. It provides highly accurate syntax highlighting for almost any mainstream programming language without requiring manual maintenance of regular expressions, CSS, or HTML. It is designed to evolve alongside VS Code's language and theme updates.Overview of Shiki syntax highlighter
mainShiki is a high-quality syntax highlighter that uses TextMate grammars to provide accurate and powerful code highlighting. It is designed to produce beautiful, production-ready syntax highlighting for web applications.Use @shikijs/engine-javascript for regex processing
mainThe@shikijs/engine-javascriptpackage provides a regex engine for Shiki that utilizes JavaScript's nativeRegExpimplementation. It achieves compatibility with Shiki's requirements by usingoniguruma-to-esto transpile Oniguruma regex syntax and behavior into native JavaScript regex. This is a suitable engine choice when you want to avoid the overhead of a WebAssembly-based engine like Oniguruma and prefer using the host environment's native regex capabilities.Use @shikijs/engine-oniguruma for WebAssembly-based RegExp engine
mainThe@shikijs/engine-onigurumapackage provides a Shiki engine that uses the Oniguruma RegExp engine implemented in WebAssembly. This is useful when you need advanced regular expression features that might not be available in the standard JavaScript RegExp engine, or when you require consistent regex behavior across different environments.Use Shiki with Monaco Editor via @shikijs/monaco
mainThe@shikijs/monacopackage allows you to use Shiki to provide high-quality syntax highlighting for the Monaco Editor. This integration leverages Shiki's engine to bring advanced highlighting capabilities to the editor environment.Explore Shiki integrations
mainShiki provides several official integrations for different ecosystems and tools:
- markdown-it Plugin: For use with the
markdown-itparser. - Rehype Plugin: For use with the
rehypeecosystem (common in Remark/Unified pipelines). - TypeScript Twoslash Integration: For advanced TypeScript type information in code blocks.
- Monaco Editor Syntax Highlight: For integrating Shiki highlighting into the Monaco editor.
- CLI: A command-line interface for Shiki tasks.
- Common Transformers: A collection of useful transformers for code block manipulation.
- markdown-it Plugin: For use with the
Use @shikijs/stream for streaming colorization
mainThe@shikijs/streampackage provides streaming colorization capabilities for Shiki. It is specifically designed for use cases where text is arriving in chunks, such as highlighting real-time outputs from Large Language Models (LLMs).Use Shiki with rehype via rehype-shiki
mainTherehype-shikiplugin allows you to integrate Shiki syntax highlighting into yourrehypeprocessing pipeline. This is useful when working with Markdown or HTML processing tools that userehype(such asremark-rehype). It transforms code blocks in your document into highlighted HTML using Shiki's engine.Use @shikijs/twoslash to add TypeScript Twoslash support to Shiki
main@shikijs/twoslash is a transformer for Shiki that enables TypeScript Twoslash functionality. It allows you to include interactive TypeScript type-checking annotations within your code blocks, which are then rendered via Shiki.Use @shikijs/colorized-brackets for VSCode-style bracket highlighting
main@shikijs/colorized-brackets is a transformer for Shiki that adds VSCode-style colorized brackets to your syntax highlighting. It allows you to visually distinguish matching brackets (parentheses, square brackets, curly braces, etc.) within your code snippets.Understand bundled languages and grammars
mainShiki includes a set of bundled languages redistributed via
tm-grammars. These grammars are not maintained by Shiki directly, but are sourced from thetextmate-grammars-themesrepository.If you need to load custom languages that are not part of the default bundle, you should follow the guide for loading custom languages.