Skip to content

Fix/expand chatui code highlighting 扩展 chatui 代码高亮 - #9892

Open
atqiyu wants to merge 4 commits into
AstrBotDevs:masterfrom
atqiyu:fix/expand-chatui-code-highlighting
Open

Fix/expand chatui code highlighting 扩展 chatui 代码高亮#9892
atqiyu wants to merge 4 commits into
AstrBotDevs:masterfrom
atqiyu:fix/expand-chatui-code-highlighting

Conversation

@atqiyu

@atqiyu atqiyu commented Sep 1, 2026

Copy link
Copy Markdown

Motivation / 更改动机

修改通过vibecoding完成

AstrBot ChatUI 使用精简版 Shiki 代码高亮包,以降低前端资源体积和内存占用。但该精简包缺少 C、C++、Rust、Go 等常用编程语言的语法包,导致对应 Markdown 代码块无法正常进行语法高亮,只显示为单一颜色。

本 PR 扩展精简版 Shiki bundle,使更多常用开发语言能够正常高亮,同时保留未知语言回退为纯文本的行为。

Modifications / 改动点

  • 在 ChatUI 的 Shiki 精简包中加入以下语言:

    • C
    • C++
    • C#
    • Rust
    • Go
    • Dart
    • Kotlin
    • Lua
    • PHP
    • R
    • Ruby
    • Scala
    • Swift
  • 增加常见语言别名支持,例如:

    • c++cccxxhpp
    • golang
    • rs
    • cs
    • ktkts
  • 支持带附加参数的语言标签,例如 rust:variant

  • 同步更新 T2I Shiki runtime 的语言列表,确保不同渲染路径的行为保持一致。

  • 新增 Shiki 语言归一化和代码高亮自动化测试。

  • 未引入新的第三方依赖。

  • 未改变未知语言回退为纯文本的行为。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  • 更改前 捕获
  • 更改后 捕获2

已完成以下验证:

node --test tests/*.test.mjs
41 tests passed, 0 failed

pnpm exec vue-tsc --noEmit
passed

pnpm run build:t2i-shiki-runtime
passed

pnpm run build
passed

新增测试覆盖以下场景:

  • C、C++、C#、Rust、Go、Dart、Kotlin、Lua、PHP、R、Ruby、Scala、Swift 均可被 Shiki 正确识别。
  • 常见语言别名能够正确归一化。
  • 代码高亮输出包含 Shiki token 样式。
  • 未知语言仍会安全回退为纯文本。

———

Checklist / 检查清单

  • If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • My changes have been well-tested, and verification results have been provided above.
    / 我的更改经过了充分测试,并已在上方提供验证结果。

  • I have ensured that no new dependencies are introduced.
    / 我确保没有引入新的依赖库。

  • My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Expand Shiki language support and normalization so common programming-language code blocks render with syntax highlighting across ChatUI rendering paths.

New Features:

  • Expand ChatUI and T2I Shiki highlighting to support C, C++, C#, Rust, Go, Dart, Kotlin, Lua, PHP, R, Ruby, Scala, and Swift.
  • Recognize common language aliases and parameterized language labels during code-block highlighting.

Bug Fixes:

  • Restore syntax highlighting for code blocks written in the newly supported languages while preserving plain-text fallback for unknown languages.

Enhancements:

  • Keep the browser and T2I Shiki language configurations aligned through shared language support and normalization behavior.

Tests:

  • Add automated coverage for language normalization, aliases, supported-language detection, syntax token output, and unknown-language fallback.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="dashboard/scripts/build-t2i-shiki-runtime.mjs" line_range="32" />
<code_context>
   cts: "typescript",
+  cs: "csharp",
   dockerfile: "bash",
+  golang: "go",
+  h: "c",
+  "h++": "cpp",
</code_context>
<issue_to_address>
**issue (broader_impact):** The T2I runtime aliases `golang` to `go`, but `go` is absent from `languageSpecs`, so the generated highlighter contains no Go grammar and its supported-language set excludes `go`. Go and `golang` code blocks therefore fall back to plain text or trigger the rendering fallback instead of being highlighted in the T2I path.

**Triggers:** When a T2I code block uses `go` or `golang`.

**Suggested fix:** Add `["go", "go"]` to `languageSpecs` before generating `shiki_runtime.iife.js`.

```suggestion
  ["go", "go"],
  ["javascript", "javascript"],
```
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: dashboard/scripts/build-t2i-shiki-runtime.mjs:32


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dashboard/scripts/build-t2i-shiki-runtime.mjs

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant