chore: standardize project comments in English

This commit is contained in:
eezd committed 2026-10-26 22:52:12 +08:00
1 parent a874a39ea5
commit ccb16acbea
167 files changed
+820 -820

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ const CACHE_LIMIT = 500
let worker: Worker | undefined
let nextId = 1
const pending = new Map<number, { resolve: (tokens: TokenRun | null) => void, reject: (reason: unknown) => void }>()
// 以"语言 + 代码"为键缓存结果;Map 保持插入顺序,超限时淘汰最早的条目
// Cache by "language + code"; Map preserves insertion order, so evict the oldest entry when the limit is exceeded.
const cache = new Map<string, TokenRun | null>()
function getWorker(): Worker {
+3 -3
View File
@@ -1,4 +1,4 @@
// 主线程与高亮 Worker 之间的消息格式
// Message format between the main thread and highlight Worker.
export interface HighlightRequest {
id: number
@@ -6,8 +6,8 @@ export interface HighlightRequest {
code: string
}
// 保留 highlight.js 的嵌套 token 与原文,编辑器使用官方 token 类样式。
// Preserve highlight.js nested tokens and source text; the editor uses official token-class styles.
export type TokenRun = (string | { classes: string, content: TokenRun })[]
// 语言不受支持时 tokens 为 null;实际失败必须与纯文本结果区分。
// tokens is null for unsupported languages; actual failures must remain distinct from plain-text results.
export type HighlightResponse = { id: number, tokens: TokenRun | null } | { id: number, error: Error }
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-template-curly-in-string -- 测试样例需要保留源码中的模板插值。 */
/* eslint-disable no-template-curly-in-string -- Test fixtures must retain source template interpolation. */
import type { HighlightResponse, TokenRun } from './protocol'
import { afterAll, beforeAll, expect, it, vi } from 'vitest'
+2 -2
View File
@@ -1,7 +1,7 @@
import type { HighlightRequest, HighlightResponse, TokenRun } from './protocol'
import hljs from 'highlight.js'
// 只转换 highlight.js 生成的 span 和转义文本,不向编辑器插入 HTML。
// Convert only highlight.js-generated spans and escaped text; never insert HTML into the editor.
function serialize(html: string): TokenRun {
const root: TokenRun = []
const stack = [root]
@@ -23,7 +23,7 @@ function serialize(html: string): TokenRun {
function highlight(req: HighlightRequest): TokenRun | null {
if (!hljs.getLanguage(req.lang)) return null
const result = hljs.highlight(req.code, { language: req.lang, ignoreIllegals: true })
// 库的安全模式会随纯文本结果返回异常,仍需传递真实失败原因。
// The library's safe mode may return an exception alongside plain text; propagate the actual failure.
if (result.errorRaised) throw result.errorRaised
return serialize(result.value)
}