// Package markup renders markdown then sanitizes it, and never trusts the renderer. Chapter 42. package markup import ( "bytes" "html" "io" "strconv" "strings" "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" xhtml "golang.org/x/net/html" "golang.org/x/net/html/atom" ) // allowed is chapter 42.1's list, and an allowlist, so it strips elements not yet invented. var allowed = map[atom.Atom]bool{ atom.P: true, atom.Br: true, atom.Strong: true, atom.Em: true, atom.Del: true, atom.Code: true, atom.Pre: true, atom.Blockquote: true, atom.H1: true, atom.H2: true, atom.H3: true, atom.H4: true, atom.H5: true, atom.H6: true, atom.Ul: true, atom.Ol: true, atom.Li: true, atom.A: true, atom.Img: true, atom.Table: true, atom.Thead: true, atom.Tbody: true, atom.Tr: true, atom.Th: true, atom.Td: true, atom.Hr: true, } // allowedAttrs is the complete attribute list from chapter 42.1. var allowedAttrs = map[atom.Atom]map[string]bool{ atom.A: {"href": true, "title": true}, atom.Img: {"src": true, "alt": true, "title": true}, atom.Code: {"class": true}, // language-* only, checked below atom.Ol: {"start": true}, // digits only, checked below } // dropWhole takes the contents too, or a stripped