diff options
author | Łukasz Hanuszczak <lukasz.hanuszczak@gmail.com> | 2015-07-01 00:47:32 +0200 |
---|---|---|
committer | Łukasz Hanuszczak <lukasz.hanuszczak@gmail.com> | 2015-07-01 00:47:32 +0200 |
commit | 395a9c3941f8b8891cffa5c17e1f6ae414edaa79 (patch) | |
tree | 30c6bad02b7fcf68701e7672503eeff7d335c473 /hypsrc-test/Utils.hs | |
parent | 40d0a050c81ff21949fc7eeede4e0dbb3b1d7c98 (diff) |
Make hyperlinker test runner strip local links from generated source.
Diffstat (limited to 'hypsrc-test/Utils.hs')
-rw-r--r-- | hypsrc-test/Utils.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/hypsrc-test/Utils.hs b/hypsrc-test/Utils.hs new file mode 100644 index 00000000..cf3e94ea --- /dev/null +++ b/hypsrc-test/Utils.hs @@ -0,0 +1,26 @@ +module Utils + ( stripLocalAnchors + , stripLocalLinks + , stripLocalReferences + ) where + + +import Data.List + + +replaceBetween :: Eq a => [a] -> a -> [a] -> [a] -> [a] +replaceBetween _ _ _ [] = [] +replaceBetween pref end val html@(x:xs') = case stripPrefix pref html of + Just strip -> pref ++ val ++ (replaceBetween' . dropWhile (/= end)) strip + Nothing -> x:(replaceBetween' xs') + where + replaceBetween' = replaceBetween pref end val + +stripLocalAnchors :: String -> String +stripLocalAnchors = replaceBetween "<a name=\"local-" '\"' "0" + +stripLocalLinks :: String -> String +stripLocalLinks = replaceBetween "<a href=\"#local-" '\"' "0" + +stripLocalReferences :: String -> String +stripLocalReferences = stripLocalLinks . stripLocalAnchors |