microcosm-cc / bluemonday

bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS
https://github.com/microcosm-cc/bluemonday
BSD 3-Clause "New" or "Revised" License
3.08k stars 178 forks source link

How to retain URL? #185

Closed psic4t closed 11 months ago

psic4t commented 11 months ago

How can I strip all tags, but retain the URLs?

I like to turn<a href="https://some.site">Some site</a> to http://some.site

buro9 commented 11 months ago

that isn't what this library is for, but you can use https://pkg.go.dev/golang.org/x/net/html to achieve this as you'll want to enumerate all tokens, only act on A elements and read just the href attribute.