Files
Memoh/internal/channel/format.go
Menci 36d50738b5 fix(channel): consistent markdown rendering across all Telegram paths (#210)
- Extract ContainsMarkdown to shared channel package
- Auto-detect markdown in normalizeOutboundMessage and MCP send tool
- Apply markdown-to-HTML conversion during streaming deltas, not just
  on the final message
- Remove resolveTelegramParseMode which incorrectly returned Telegram's
  native "Markdown" mode instead of converting to HTML
- Fix all 14 Telegram send/edit paths for consistent parse mode handling
- Reset parseMode for plain-text error messages to avoid HTML corruption
2026-03-09 13:06:44 +08:00

31 lines
547 B
Go

package channel
import (
"regexp"
"strings"
)
// ContainsMarkdown returns true if the text contains common Markdown constructs.
func ContainsMarkdown(text string) bool {
if strings.TrimSpace(text) == "" {
return false
}
patterns := []string{
`\*\*[^*]+\*\*`,
`\*[^*]+\*`,
`~~[^~]+~~`,
"`[^`]+`",
"```[\\s\\S]*```",
`\[.+\]\(.+\)`,
`(?m)^#{1,6}\s`,
`(?m)^[-*]\s`,
`(?m)^\d+\.\s`,
}
for _, pattern := range patterns {
if matched, _ := regexp.MatchString(pattern, text); matched {
return true
}
}
return false
}