aboutsummaryrefslogtreecommitdiff
path: root/hypsrc-test/Utils.hs
diff options
context:
space:
mode:
authoridontgetoutmuch <dominic@steinitz.org>2015-12-20 21:01:47 +0000
committeridontgetoutmuch <dominic@steinitz.org>2015-12-20 21:01:47 +0000
commit2bdfda1fb2e0de696ca8c6f7a152b2f85a541be9 (patch)
treecc29895f7d69f051cfec172bb0f8c2ef03552789 /hypsrc-test/Utils.hs
parent5a57a24c44e06e964c4ea2276c842c722c4e93d9 (diff)
parentfa03f80d76f1511a811a0209ea7a6a8b6c58704f (diff)
Merge pull request #1 from haskell/ghc-head
Ghc head
Diffstat (limited to 'hypsrc-test/Utils.hs')
-rw-r--r--hypsrc-test/Utils.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/hypsrc-test/Utils.hs b/hypsrc-test/Utils.hs
new file mode 100644
index 00000000..e15fabee
--- /dev/null
+++ b/hypsrc-test/Utils.hs
@@ -0,0 +1,47 @@
+{-# LANGUAGE CPP #-}
+
+
+module Utils
+ ( baseDir, rootDir
+ , srcDir, refDir, outDir, refDir', outDir'
+ , haddockPath
+ , stripLocalAnchors, stripLocalLinks, stripLocalReferences
+ ) where
+
+
+import Data.List
+
+import System.FilePath
+
+
+baseDir, rootDir :: FilePath
+baseDir = takeDirectory __FILE__
+rootDir = baseDir </> ".."
+
+srcDir, refDir, outDir, refDir', outDir' :: FilePath
+srcDir = baseDir </> "src"
+refDir = baseDir </> "ref"
+outDir = baseDir </> "out"
+refDir' = refDir </> "src"
+outDir' = outDir </> "src"
+
+haddockPath :: FilePath
+haddockPath = rootDir </> "dist" </> "build" </> "haddock" </> "haddock"
+
+
+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