[commit: haddock] 2.17.3.1-spanfix, alexbiehl-patch-1, ghc-8.0, ghc-8.0-facebook, ghc-head, ghc-head1, haddock-quick, headdock-library-1.4.5, ie_avails, issue-303, issue-475, master, pr-filter-maps, pr/cabal-desc, travis, v2.17, v2.17.3, v2.18, wip-located-module-as, wip/D2418, wip/T11080-open-data-kinds, wip/T11430, wip/T12105, wip/T12105-2, wip/T12942, wip/T13163, wip/T14529, wip/T3384, wip/embelleshed-rdr, wip/new-tree-one-param, wip/rae, wip/remove-frames, wip/remove-frames1, wip/revert-ttg-2017-11-20, wip/ttg-2017-10-13, wip/ttg-2017-10-31, wip/ttg-2017-11-06, wip/ttg2-2017-11-10, wip/ttg3-2017-11-12, wip/ttg4-constraints-2017-11-13, wip/ttg6-unrevert-2017-11-22: Implement utility functions for conditional link stripping. (1cb714e)

git at git.haskell.org git at git.haskell.org
Tue Nov 28 11:38:22 UTC 2017


Repository : ssh://git@git.haskell.org/haddock

On branches: 2.17.3.1-spanfix,alexbiehl-patch-1,ghc-8.0,ghc-8.0-facebook,ghc-head,ghc-head1,haddock-quick,headdock-library-1.4.5,ie_avails,issue-303,issue-475,master,pr-filter-maps,pr/cabal-desc,travis,v2.17,v2.17.3,v2.18,wip-located-module-as,wip/D2418,wip/T11080-open-data-kinds,wip/T11430,wip/T12105,wip/T12105-2,wip/T12942,wip/T13163,wip/T14529,wip/T3384,wip/embelleshed-rdr,wip/new-tree-one-param,wip/rae,wip/remove-frames,wip/remove-frames1,wip/revert-ttg-2017-11-20,wip/ttg-2017-10-13,wip/ttg-2017-10-31,wip/ttg-2017-11-06,wip/ttg2-2017-11-10,wip/ttg3-2017-11-12,wip/ttg4-constraints-2017-11-13,wip/ttg6-unrevert-2017-11-22
Link       : http://git.haskell.org/haddock.git/commitdiff/1cb714e35337a6b17d7fc37f086914f43f7f2da3

>---------------------------------------------------------------

commit 1cb714e35337a6b17d7fc37f086914f43f7f2da3
Author: Ɓukasz Hanuszczak <lukasz.hanuszczak at gmail.com>
Date:   Fri Aug 14 20:41:41 2015 +0200

    Implement utility functions for conditional link stripping.


>---------------------------------------------------------------

1cb714e35337a6b17d7fc37f086914f43f7f2da3
 haddock-test/src/Test/Haddock/Xhtml.hs | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/haddock-test/src/Test/Haddock/Xhtml.hs b/haddock-test/src/Test/Haddock/Xhtml.hs
index b694149..d8c2624 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



More information about the ghc-commits mailing list