highlight

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 5 Imported by: 0

README

ui/highlight

English | 简体中文

Code highlighting, optional modules. The syntax coloring of CodeEditor, TextView and Markdown code blocks all comes from here; when not introduced, the code is displayed as plain text and other functions are not affected.

import _ "github.com/dyike/keel/ui/highlight"
  • Why is it packaged separately: It uses chroma, built-in rules for hundreds of languages, all registered at startup, cannot be deleted by the linker, and occupies about 4 MB. Applications that do not display codes do not need to be brought.
  • Dependencies: ui/core (implements core.Highlighter and core.SetHighlighter in init) and chroma.
  • The language name supports aliases and extensions (go, golang, Go); the default color matching is github / github-dark, which can be selected according to the depth of the code background. Markdown can use markdown.CodeStyle to specify the chroma style name.

To change to another highlighting implementation, implement core.Highlighter and call core.SetHighlighter.

Documentation

Overview

Package highlight colors source code in CodeEditor, TextView and Markdown code blocks. Import it for its side effect where the app shows code:

import _ "github.com/dyike/keel/ui/highlight"

It is separate because its lexers (chroma, hundreds of languages) add about 4 MB to a binary; without it code shows as plain text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chroma

type Chroma struct{}

Chroma is the core.Highlighter this package installs.

func (Chroma) Highlight

func (Chroma) Highlight(code string, o core.HighlightOptions) ([]core.CodeToken, bool)

Highlight tokenizes code; Style names a chroma style, defaulting to github or github-dark.

func (Chroma) Language

func (Chroma) Language(name string) string

Language is chroma's name for a language, alias or extension.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL