aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Backends
diff options
context:
space:
mode:
authorƁukasz Hanuszczak <lukasz.hanuszczak@gmail.com>2015-07-25 18:54:30 +0200
committerMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2015-08-02 23:32:14 +0100
commit7e8330944666064f12f067970de2936b58589785 (patch)
tree9bf74e82bf3dca7e6c8a4792ec3cd9496f187bef /haddock-api/src/Haddock/Backends
parentc274363d5d868c838c382a52428c667090514f86 (diff)
Add some utility definitions for generating line anchors.
Diffstat (limited to 'haddock-api/src/Haddock/Backends')
-rw-r--r--haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs25
1 files changed, 23 insertions, 2 deletions
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
index db2bfc76..9de4a03d 100644
--- a/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
@@ -1,13 +1,18 @@
module Haddock.Backends.Hyperlinker.Utils
( hypSrcDir, hypSrcModuleFile, hypSrcModuleFile'
- , hypSrcModuleUrl, hypSrcModuleUrl', hypSrcNameUrl, hypSrcModuleNameUrl
- , hypSrcModuleUrlFormat, hypSrcModuleNameUrlFormat,
+ , hypSrcModuleUrl, hypSrcModuleUrl'
+ , hypSrcNameUrl
+ , hypSrcLineUrl
+ , hypSrcModuleNameUrl, hypSrcModuleLineUrl
+ , hypSrcModuleUrlFormat
+ , hypSrcModuleNameUrlFormat, hypSrcModuleLineUrlFormat
) where
import Haddock.Backends.Xhtml.Utils
import GHC
+import FastString
import System.FilePath.Posix ((</>))
@@ -31,17 +36,33 @@ hypSrcNameUrl :: Name -> String
hypSrcNameUrl name = spliceURL
Nothing Nothing (Just name) Nothing nameFormat
+hypSrcLineUrl :: Int -> String
+hypSrcLineUrl line = spliceURL
+ Nothing Nothing Nothing (Just spn) lineFormat
+ where
+ loc = mkSrcLoc nilFS line 1
+ spn = mkSrcSpan loc loc
+
hypSrcModuleNameUrl :: Module -> Name -> String
hypSrcModuleNameUrl mdl name = hypSrcModuleUrl mdl ++ "#" ++ hypSrcNameUrl name
+hypSrcModuleLineUrl :: Module -> Int -> String
+hypSrcModuleLineUrl mdl line = hypSrcModuleUrl mdl ++ "#" ++ hypSrcLineUrl line
+
hypSrcModuleUrlFormat :: String
hypSrcModuleUrlFormat = hypSrcDir </> moduleFormat
hypSrcModuleNameUrlFormat :: String
hypSrcModuleNameUrlFormat = hypSrcModuleUrlFormat ++ "#" ++ nameFormat
+hypSrcModuleLineUrlFormat :: String
+hypSrcModuleLineUrlFormat = hypSrcModuleUrlFormat ++ "#" ++ lineFormat
+
moduleFormat :: String
moduleFormat = "%{MODULE}.html"
nameFormat :: String
nameFormat = "%{NAME}"
+
+lineFormat :: String
+lineFormat = "line-%{LINE}"