Files
masyunis/lib/challenge/challengepage/explanation.go
T
sol_bot Bot e07de898cd Import Anubis v1.28.2
Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3).
Masyunis customizations are re-applied in the following commits.
2026-11-28 14:52:26 +03:00

21 lines
759 B
Go

package challengepage
import (
"html"
"regexp"
)
//go:generate go tool github.com/a-h/templ/cmd/templ generate
// wikipediaLink matches an escaped Wikipedia anchor tag in translated text.
// The URL character set is restricted so that nothing in it can break out of
// the href attribute.
var wikipediaLink = regexp.MustCompile(`<a href="(https://[a-z-]{2,12}\.wikipedia\.org/wiki/[A-Za-z0-9_-]+)">(.*?)</a>`)
// explanationHTML escapes translated text and then restores only anchor tags
// pointing at Wikipedia. Translations are community-contributed, so they must
// never be rendered as raw HTML.
func explanationHTML(text string) string {
return wikipediaLink.ReplaceAllString(html.EscapeString(text), `<a href="$1">$2</a>`)
}