aboutsummaryrefslogtreecommitdiff
path: root/haddock-test/src/Test/Haddock/Xhtml.hs
diff options
context:
space:
mode:
authorŁukasz Hanuszczak <lukasz.hanuszczak@gmail.com>2015-08-13 12:21:45 +0200
committerŁukasz Hanuszczak <lukasz.hanuszczak@gmail.com>2015-08-22 23:40:27 +0200
commit4a4d9ecf66bcb6561f7b10c07742c4b6688332b8 (patch)
tree5e5369f8bc84006acfdf995ca74865a99e447f68 /haddock-test/src/Test/Haddock/Xhtml.hs
parent7196607a71a1ab1ef9e40f8eab2f27888c7290c2 (diff)
Refactor HTML test suite boilerplate to external package.
Diffstat (limited to 'haddock-test/src/Test/Haddock/Xhtml.hs')
-rw-r--r--haddock-test/src/Test/Haddock/Xhtml.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/haddock-test/src/Test/Haddock/Xhtml.hs b/haddock-test/src/Test/Haddock/Xhtml.hs
new file mode 100644
index 00000000..35f5910a
--- /dev/null
+++ b/haddock-test/src/Test/Haddock/Xhtml.hs
@@ -0,0 +1,49 @@
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE StandaloneDeriving #-}
+
+
+module Test.Haddock.Xhtml where
+
+
+import Control.Monad
+
+import Data.Generics.Aliases
+import Data.Generics.Schemes
+
+import Text.XML.Light
+
+
+deriving instance Eq Content
+deriving instance Eq Element
+deriving instance Eq CData
+
+
+readXml :: FilePath -> IO (Maybe Element)
+readXml = liftM parseXMLDoc . readFile
+
+
+strip :: Element -> Element
+strip = stripFooter . stripLinks
+
+
+stripLinks :: Element -> Element
+stripLinks =
+ everywhere (mkT unlink)
+ where
+ unlink attr@(Attr { attrKey = key })
+ | qName key == "href" = attr { attrVal = "#" }
+ | otherwise = attr
+
+
+stripFooter :: Element -> Element
+stripFooter =
+ everywhere (mkT defoot)
+ where
+ defoot elem
+ | isFooter elem = elem { elContent = [] }
+ | otherwise = elem
+ isFooter elem = any isFooterAttr $ elAttribs elem
+ isFooterAttr (Attr { .. }) = and
+ [ qName attrKey == "id"
+ , attrVal == "footer"
+ ]