mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
36d50738b5
- 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
31 lines
547 B
Go
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
|
|
}
|