aboutsummaryrefslogtreecommitdiff
path: root/hypsrc-test/Utils.hs
blob: cf3e94ea114233a20fa8045f1d998fd5da9185bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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