aboutsummaryrefslogtreecommitdiff
path: root/haddock-test/src/Test
diff options
context:
space:
mode:
Diffstat (limited to 'haddock-test/src/Test')
-rw-r--r--haddock-test/src/Test/Haddock/Xhtml.hs27
1 files changed, 22 insertions, 5 deletions
diff --git a/haddock-test/src/Test/Haddock/Xhtml.hs b/haddock-test/src/Test/Haddock/Xhtml.hs
index b6941496..d8c26249 100644
--- a/haddock-test/src/Test/Haddock/Xhtml.hs
+++ b/haddock-test/src/Test/Haddock/Xhtml.hs
@@ -5,7 +5,7 @@
module Test.Haddock.Xhtml
( Xhtml(..)
, parseXhtml, dumpXhtml
- , stripLinks, stripFooter
+ , stripLinks, stripLinksWhen, stripAnchorsWhen, stripFooter
) where
@@ -35,14 +35,31 @@ dumpXhtml = ppElement . xhtmlElement
stripLinks :: Xhtml -> Xhtml
-stripLinks =
- Xhtml . everywhere (mkT unlink) . xhtmlElement
+stripLinks = stripLinksWhen (const True)
+
+
+stripLinksWhen :: (String -> Bool) -> Xhtml -> Xhtml
+stripLinksWhen p =
+ processAnchors unlink
+ where
+ unlink attr@(Attr { attrKey = key, attrVal = val })
+ | qName key == "href" && p val = attr { attrVal = "#" }
+ | otherwise = attr
+
+
+stripAnchorsWhen :: (String -> Bool) -> Xhtml -> Xhtml
+stripAnchorsWhen p =
+ processAnchors unname
where
- unlink attr@(Attr { attrKey = key })
- | qName key == "href" = attr { attrVal = "#" }
+ unname attr@(Attr { attrKey = key, attrVal = val })
+ | qName key == "name" && p val = attr { attrVal = "" }
| otherwise = attr
+processAnchors :: (Attr -> Attr) -> Xhtml -> Xhtml
+processAnchors f = Xhtml . everywhere (mkT f) . xhtmlElement
+
+
stripFooter :: Xhtml -> Xhtml
stripFooter =
Xhtml . everywhere (mkT defoot) . xhtmlElement