ui/highlight
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(implementscore.Highlighterandcore.SetHighlighterininit) and chroma. - The language name supports aliases and extensions (
go,golang,Go); the default color matching isgithub/github-dark, which can be selected according to the depth of the code background. Markdown can usemarkdown.CodeStyleto specify the chroma style name.
To change to another highlighting implementation, implement core.Highlighter and call core.SetHighlighter.
For Go-only applications, import ui/highlight/golang instead. It includes Go, Go text templates and plain text, with the same token conversion and styles; other languages are uncolored. The full provider here is unchanged.