fix: removeCodeBlocks 给每行末尾追加 \n 导致发送消息多一个换行

改为用 strings.Join 拼接,只在行间加 \n,末行不追加。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 13:05:52 +08:00
parent 7e29be8ae3
commit e5f8e42a78
@@ -594,20 +594,17 @@ func removeHeadings(s string) string {
} }
func removeCodeBlocks(s string) string { func removeCodeBlocks(s string) string {
result := "" var kept []string
inCode := false inCode := false
for _, line := range splitLines(s) { for _, line := range splitLines(s) {
if hasPrefix(line, "```") { if hasPrefix(line, "```") {
inCode = !inCode inCode = !inCode
continue continue
} }
if inCode { kept = append(kept, line)
result += line + "\n"
} else {
result += line + "\n"
}
} }
return result _ = inCode
return strings.Join(kept, "\n")
} }
func splitLines(s string) []string { func splitLines(s string) []string {