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); htmlPolicy then sanitizes the // rendered result on every write path. goldmark.WithRendererOptions(html.WithUnsafe()), ) // htmlPolicy is the allow-list for stored journal HTML. htmlPolicy = newHTMLPolicy() ) // newHTMLPolicy extends bluemonday's UGC policy only with what goldmark // renders and what the imported posts and categories use. func newHTMLPolicy() *bluemonday.Policy { p := bluemonday.UGCPolicy() // Winter neither adds nor requires rel="nofollow", so links keep their // stored form. p.RequireNoFollowOnLinks(false) // Imported author footers: