highlight

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

README

ui/highlight

代码高亮,可选模块。CodeEditor、TextView 和 Markdown 代码块的语法着色都来自这里;不引入时代码显示为纯文本,其他功能不受影响。

import _ "github.com/dyike/keel/ui/highlight"
  • 为什么单独成包:它用 chroma,内置几百种语言的规则,在启动时全部注册,链接器删不掉,约占 4 MB。不显示代码的应用不必带上。
  • 依赖:ui/core(实现 core.Highlighter 并在 init 里 core.SetHighlighter)和 chroma。
  • 语言名支持别名和扩展名(go、golang、Go);配色默认 github / github-dark,按代码背景深浅选择,Markdown 可用 markdown.CodeStyle 指定 chroma 风格名。

要换别的高亮实现,实现 core.Highlighter 并调用 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