Skip to content

Instantly share code, notes, and snippets.

@Akii
Created October 19, 2019 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akii/3323ddb9898c3e310fdf0536b7747835 to your computer and use it in GitHub Desktop.
Save Akii/3323ddb9898c3e310fdf0536b7747835 to your computer and use it in GitHub Desktop.
TagSoup removing all script tags and adding a base tag
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