Created
October 19, 2019 12:37
-
-
Save Akii/3323ddb9898c3e310fdf0536b7747835 to your computer and use it in GitHub Desktop.
TagSoup removing all script tags and adding a base tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.ByteString.Lazy as LBS | |
import Text.HTML.TagSoup | |
import Text.HTML.TagSoup.Tree | |
addBaseTag :: LBS.ByteString -> [TagTree LBS.ByteString] -> [TagTree LBS.ByteString] | |
addBaseTag href = transformTree f | |
where | |
f (TagBranch "head" attrs subTrees) = [TagBranch "head" attrs (baseTag : subTrees)] | |
f x = [x] | |
baseTag = TagLeaf (TagOpen "base" [("href", href)]) | |
removeScripts :: [TagTree LBS.ByteString] -> [TagTree LBS.ByteString] | |
removeScripts = transformTree f | |
where | |
f (TagBranch "script" _ _) = [] | |
f x = [x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment