mirror of
https://github.com/eryajf/chatgpt-dingtalk.git
synced 2026-04-22 23:47:15 +08:00
fix: html escape (#222)
Co-authored-by: stoneflying <stonelife98@gmail.com>
This commit is contained in:
@@ -253,20 +253,19 @@ func FormatTimeDuation(duration time.Duration) string {
|
||||
func FormatMarkdown(md string) string {
|
||||
lines := strings.Split(md, "\n")
|
||||
codeblock := false
|
||||
existHtml := strings.Contains(md, "<")
|
||||
|
||||
for i, line := range lines {
|
||||
if strings.HasPrefix(line, "```") {
|
||||
codeblock = !codeblock
|
||||
}
|
||||
if codeblock {
|
||||
lines[i] = strings.ReplaceAll(line, "#", "\\#")
|
||||
}
|
||||
}
|
||||
// 如果Markdown内存在html,将Markdown中的html标签转义
|
||||
if strings.Contains(md, "<") {
|
||||
for i, line := range lines {
|
||||
} else if existHtml {
|
||||
lines[i] = html.EscapeString(line)
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user