Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit d028459

Browse files
committed
Fix #1206 by passing instance name as anchor
(cherry picked from commit 88106cb)
1 parent 49a14c8 commit d028459

File tree

4 files changed

+541
-10
lines changed

4 files changed

+541
-10
lines changed

haddock-api/src/Haddock/Backends/Xhtml/Decl.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,12 @@ ppInstances links origin instances splice unicode pkg qual
634634
-- force Splice = True to use line URLs
635635
where
636636
instName = getOccString origin
637-
instDecl :: Int -> DocInstance DocNameI -> (SubDecl, Maybe Module, Located DocName)
637+
instDecl :: Int -> DocInstance DocNameI -> (String, SubDecl, Maybe Module, Located DocName)
638638
instDecl no (inst, mdoc, loc, mdl) =
639-
((ppInstHead links splice unicode qual mdoc origin False no inst mdl), mdl, loc)
640-
639+
(instanceAnchor, mModule, mdl, loc)
640+
where
641+
instanceAnchor = getOccString (ihdClsName inst) <> "_" <> show no <> ":"
642+
mModule = ppInstHead links splice unicode qual mdoc origin False no inst mdl
641643

642644
ppOrphanInstances :: LinksInfo
643645
-> [DocInstance DocNameI]
@@ -649,9 +651,12 @@ ppOrphanInstances links instances splice unicode pkg qual
649651
instOrigin :: InstHead name -> InstOrigin (IdP name)
650652
instOrigin inst = OriginClass (ihdClsName inst)
651653

652-
instDecl :: Int -> DocInstance DocNameI -> (SubDecl, Maybe Module, Located DocName)
654+
instDecl :: Int -> DocInstance DocNameI -> (String, SubDecl, Maybe Module, Located DocName)
653655
instDecl no (inst, mdoc, loc, mdl) =
654-
((ppInstHead links splice unicode qual mdoc (instOrigin inst) True no inst Nothing), mdl, loc)
656+
(instanceAnchor, mModule, mdl, loc)
657+
where
658+
instanceAnchor = getOccString (ihdClsName inst) <> "_" <> show no <> ":"
659+
mModule = ppInstHead links splice unicode qual mdoc (instOrigin inst) True no inst Nothing
655660

656661

657662
ppInstHead :: LinksInfo -> Splice -> Unicode -> Qualification

haddock-api/src/Haddock/Backends/Xhtml/Layout.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,16 @@ subTable pkg qual decls = Just $ table << aboves (concatMap subRow decls)
153153

154154
-- | Sub table with source information (optional).
155155
subTableSrc :: Maybe Package -> Qualification -> LinksInfo -> Bool
156-
-> [(SubDecl, Maybe Module, Located DocName)] -> Maybe Html
156+
-> [(String, SubDecl, Maybe Module, Located DocName)] -> Maybe Html
157157
subTableSrc _ _ _ _ [] = Nothing
158158
subTableSrc pkg qual lnks splice decls = Just $ table << aboves (concatMap subRow decls)
159159
where
160-
subRow ((decl, mdoc, subs), mdl, L loc dn) =
160+
subRow (instanchor, (decl, mdoc, subs), mdl, L loc dn) =
161161
(td ! [theclass "src clearfix"] <<
162162
(thespan ! [theclass "inst-left"] << decl)
163163
<+> linkHtml loc mdl dn
164164
<->
165-
docElement td << fmap (docToHtml Nothing pkg qual) mdoc
165+
docElement td << fmap (docToHtml (Just instanchor) pkg qual) mdoc
166166
)
167167
: map (cell . (td <<)) subs
168168

@@ -201,7 +201,7 @@ subEquations pkg qual = divSubDecls "equations" "Equations" . subTable pkg qual
201201
subInstances :: Maybe Package -> Qualification
202202
-> String -- ^ Class name, used for anchor generation
203203
-> LinksInfo -> Bool
204-
-> [(SubDecl, Maybe Module, Located DocName)] -> Html
204+
-> [(String, SubDecl, Maybe Module, Located DocName)] -> Html
205205
subInstances pkg qual nm lnks splice = maybe noHtml wrap . instTable
206206
where
207207
wrap contents = subSection (hdr +++ collapseDetails id_ DetailsOpen (summary +++ contents))
@@ -214,7 +214,7 @@ subInstances pkg qual nm lnks splice = maybe noHtml wrap . instTable
214214

215215
subOrphanInstances :: Maybe Package -> Qualification
216216
-> LinksInfo -> Bool
217-
-> [(SubDecl, Maybe Module, Located DocName)] -> Html
217+
-> [(String, SubDecl, Maybe Module, Located DocName)] -> Html
218218
subOrphanInstances pkg qual lnks splice = maybe noHtml wrap . instTable
219219
where
220220
wrap = ((h1 << "Orphan instances") +++)

0 commit comments

Comments
 (0)