package classes import ( "bytes" "errors" "fmt" "io" "regexp" "slices" "strings" "github.com/microcosm-cc/bluemonday" "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer/html" xhtml "golang.org/x/net/html" ) var ( markdownEngine = goldmark.New( goldmark.WithExtensions(extension.Footnote, extension.Table), goldmark.WithParserOptions(parser.WithAttribute()), // Winter's Markdown::parse passes raw HTML through, so imported HTML // bodies round-trip (D-03, PHP parity); the registry HTML policy then // sanitizes the rendered result on every write path. goldmark.WithRendererOptions(html.WithUnsafe()), ) // htmlPolicy is the default youtube-only bluemonday policy. htmlPolicy = defaultEmbedRegistry.Policy() ) // newHTMLPolicyFor extends bluemonday's UGC policy only with what goldmark // renders, what imported posts and categories use, and the registered embed // providers. func newHTMLPolicyFor(providers []compiledEmbedProvider) *bluemonday.Policy { p := bluemonday.UGCPolicy() // Winter neither adds nor requires rel="nofollow", so links keep their // stored form. p.RequireNoFollowOnLinks(false) // Imported author footers: