Discover Packages
github.com/CarlOpenLab/Gloss
internal
highlight
package
Version:
v0.3.3
Opens a new window with list of versions in this module.
Published: Oct 14, 2026
License: MIT
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0 modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
Documentation
Documentation
¶
Package highlight 用 chroma 把源码切成带类型的片段,供界面按行上色。
只做「哪一段是什么 token」,不决定颜色:同一份切分结果在浅色和深色
主题下都能用,颜色在渲染时按当前主题查。这样切换主题不需要重新切分。
NeedHighlight 判断这个文件名值不值得高亮。
词法器认不出来的一律走纯文本。chroma 会把 .txt 之类也认成 plaintext
词法器,那种「高亮」只是把每行标成 Text,白跑一遍切分,所以按名字挡掉。
Style 按明暗取配色方案。名字不存在时 chroma 会退回默认方案,
不会返回 nil。
Entry 是渲染一段文字需要的样式。
Resolve 查 token 类型在给定配色下的样式。切分本身不看样式,
所以这个函数只给测试和 Palette 用。
File 是一个文件切分好的结果,按行(从 1 开始)取用。
NewLines 切分文件内容。lines 是按行切好的内容(不含换行符)。
必须整份文件一起切:多行字符串、块注释这类结构单看一行是判断不出来的,
而 diff 恰好经常出现在这些结构附近。
Line 返回第 n 行(从 1 开始)的片段。超出范围或没有内容时返回 nil,
调用方按整行一个颜色处理即可。
Palette 是一套配色方案,缓存每个 token 类型解析好的样式。
切分结果和明暗无关,颜色却随主题变 —— 所以颜色在渲染时按当前主题
解析,解析一次就缓存下来,不必每帧对每一段重新做一遍样式继承。
Entry 返回某个片段该用什么样式。不认识的片段类型返回零值,
调用方用默认前景色即可。
Seg 是行内一段同类型的文本,区间是该行里的字节下标。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.