package runner

import (
	"regexp"
	"strings"
)

// stripMarkdown removes common markdown syntax from src, returning plain text
// suitable for TTS. Mirrors the helper in the scraper's server package.
func stripMarkdown(src string) string {
	src = regexp.MustCompile(`(?m)^#{1,6}\s+`).ReplaceAllString(src, "")
	src = regexp.MustCompile(`\*{1,3}|_{1,3}`).ReplaceAllString(src, "")
	src = regexp.MustCompile("(?s)```.*?```").ReplaceAllString(src, "")
	src = regexp.MustCompile("`[^`]*`").ReplaceAllString(src, "")
	src = regexp.MustCompile(`\[([^\]]+)\]\([^)]+\)`).ReplaceAllString(src, "$1")
	src = regexp.MustCompile(`!\[[^\]]*\]\([^)]+\)`).ReplaceAllString(src, "")
	src = regexp.MustCompile(`(?m)^>\s?`).ReplaceAllString(src, "")
	src = regexp.MustCompile(`(?m)^[-*_]{3,}\s*$`).ReplaceAllString(src, "")
	src = regexp.MustCompile(`\n{3,}`).ReplaceAllString(src, "\n\n")
	return strings.TrimSpace(src)
}
