scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

Cleaner: Clean <body> and <head> if needed #240

Closed valentinperignon closed 1 year ago

valentinperignon commented 1 year ago

👋 Hello

I would like to propose a modification to the Cleaner class. It would be nice to be able to clean the <head> as well as <body> if we need it.

Why doing this? I am working on a mail iOS app and I need to show HTML mails. When I sanitize the message, I want to clean the whole document, so <head> and <body>. On Android, the mail app k9 does the same process. They have created a HeadCleaner class: k9mail - HeadCleaner.kt which is a visitor that cleans the <head> tag. You have an example here of how I am using this : feat: Clean head and body from html document #719.

I understand it's quite a big change and SwiftSoup would be slightly different from Jsoup. This change does not break the current API at all but adds an option for those who will need it.

I need this modification for my project and rather than doing this for myself only, I thought it would be nice to create a PR if it can help other people. So you can decide if this change belongs in SwiftSoup or not 😃

scinfu commented 1 year ago

Hi, thank you, i'm marging to master. Can you change README with how to use it? Thank you.