Highlight

Free · MIT

Whether language has a grammar here.

Markdown

Preview

It's types and helpers, listed below.

Install

With the Candor CLI

First time? Get started sets up the registry and theme. Or with shadcn directly: npx shadcn@latest add @candor/highlight

Functions

canHighlight(language: string)

Whether language has a grammar here.

tokenize(text: string, language: string)

The text split into typed tokens; their texts joined give back the input exactly.

Types

TokenType
A small syntax highlighter for code an agent shows: it splits text into typed tokens (keyword, string, comment…), and Payload renders each as a span. The output is text, never HTML, so nothing in the code can run or inject markup. It covers the languages agents show most (JS/TS, Python, SQL, JSON, shell, YAML, CSS, HTML/XML, Go, Rust, Java, C) in a few kilobytes; anything else comes back as one plain token.
"keyword" | "string" | "number" | "comment" | "function" | "property" | "type" | "tag" | "variable" | "operator" | "plain"
Token
{ type: TokenType; text: string }