修复反斜杠转;代码格式
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user