修复反斜杠转;代码格式

This commit is contained in:
dela
2026-02-05 13:57:20 +08:00
parent 6691dbaff2
commit 098fd57c19
3 changed files with 20 additions and 94 deletions

View File

@@ -2,6 +2,7 @@ package toc
import (
"fmt"
"html"
"strings"
)
@@ -17,28 +18,28 @@ func (m *Manager) Render() (string, error) {
}
var sb strings.Builder
sb.WriteString("📚 **频道目录**\n")
sb.WriteString("📚 <b>频道目录</b>\n")
sb.WriteString("━━━━━━━━━━━━━━━\n\n")
if len(categories) == 0 {
sb.WriteString("_暂无分类_")
sb.WriteString("<i>暂无分类</i>")
return sb.String(), nil
}
for _, cat := range categories {
entries := entriesByCategory[cat.Name]
sb.WriteString(fmt.Sprintf("📁 **%s**", cat.Name))
sb.WriteString(fmt.Sprintf("📁 <b>%s</b>", html.EscapeString(cat.Name)))
if len(entries) > 0 {
sb.WriteString(fmt.Sprintf(" (%d)", len(entries)))
}
sb.WriteString("\n")
if len(entries) == 0 {
sb.WriteString(" _暂无内容_\n")
sb.WriteString(" <i>暂无内容</i>\n")
} else {
for _, entry := range entries {
sb.WriteString(fmt.Sprintf(" • [%s](%s)\n", escapeMarkdown(entry.Title), entry.Link))
sb.WriteString(fmt.Sprintf(" • <a href=\"%s\">%s</a>\n", entry.Link, html.EscapeString(entry.Title)))
}
}
sb.WriteString("\n")
@@ -48,16 +49,3 @@ func (m *Manager) Render() (string, error) {
return sb.String(), nil
}
func escapeMarkdown(s string) string {
replacer := strings.NewReplacer(
"[", "\\[",
"]", "\\]",
"(", "\\(",
")", "\\)",
"*", "\\*",
"_", "\\_",
"`", "\\`",
)
return replacer.Replace(s)
}