aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2020-03-28 14:12:48 -0400
committerAlec Theriault <alec.theriault@gmail.com>2020-03-28 14:26:27 -0400
commit5dc3866928759fcaf6b31d1598051781389a01d4 (patch)
tree4c7745419ef14f384a2688d96f960721f48652f1
parentd8bedeb98a84db0d51c49d41c632d9d4846d1bbe (diff)
Disallow links in section headers
This is quite straightforward to implement, since we already had a function `docToHtmlNoAnchors` (which we used to generate the link in the sidebar "Contents"). This breaks test `Bug387`, but that test case has aged badly: we now automatically generate anchors for all headings, so manually adding an anchor in a section makes no sense. Nested anchors are, as pointed out in #1054, disallowed by the HTML standard. Fixes #1054
-rw-r--r--haddock-api/src/Haddock/Backends/Xhtml.hs2
-rw-r--r--html-test/ref/Bug1054.html (renamed from html-test/ref/Bug387.html)54
-rw-r--r--html-test/src/Bug1054.hs5
-rw-r--r--html-test/src/Bug387.hs12
4 files changed, 19 insertions, 54 deletions
diff --git a/haddock-api/src/Haddock/Backends/Xhtml.hs b/haddock-api/src/Haddock/Backends/Xhtml.hs
index d30312b7..e3d4e8ca 100644
--- a/haddock-api/src/Haddock/Backends/Xhtml.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml.hs
@@ -681,7 +681,7 @@ processExport :: Bool -> LinksInfo -> Bool -> Maybe Package -> Qualification
-> ExportItem DocNameI -> Maybe Html
processExport _ _ _ _ _ ExportDecl { expItemDecl = L _ (InstD {}) } = Nothing -- Hide empty instances
processExport summary _ _ pkg qual (ExportGroup lev id0 doc)
- = nothingIf summary $ groupHeading lev id0 << docToHtml (Just id0) pkg qual (mkMeta doc)
+ = nothingIf summary $ groupHeading lev id0 << docToHtmlNoAnchors (Just id0) pkg qual (mkMeta doc)
processExport summary links unicode pkg qual (ExportDecl decl pats doc subdocs insts fixities splice)
= processDecl summary $ ppDecl summary links decl pats doc insts fixities subdocs splice unicode pkg qual
processExport summary _ _ _ qual (ExportNoDecl y [])
diff --git a/html-test/ref/Bug387.html b/html-test/ref/Bug1054.html
index 12887a83..df3fae0a 100644
--- a/html-test/ref/Bug387.html
+++ b/html-test/ref/Bug1054.html
@@ -3,7 +3,7 @@
><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
/><meta name="viewport" content="width=device-width, initial-scale=1"
/><title
- >Bug387</title
+ >Bug1054</title
><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
/><link rel="stylesheet" type="text/css" href="#"
/><link rel="stylesheet" type="text/css" href="#"
@@ -40,7 +40,7 @@
></tr
></table
><p class="caption"
- >Bug387</p
+ >Bug1054</p
></div
><div id="table-of-contents"
><div id="contents-list"
@@ -49,11 +49,9 @@
><ul
><li
><a href="#"
- >Section1</a
- ></li
- ><li
- ><a href="#"
- >Section2</a
+ >Header with <code
+ >foo</code
+ > link</a
></li
></ul
></div
@@ -65,49 +63,23 @@
><ul class="details-toggle" data-details-id="syn"
><li class="src short"
><a href="#"
- >test1</a
- > :: <a href="#" title="Data.Int"
- >Int</a
- ></li
- ><li class="src short"
- ><a href="#"
- >test2</a
- > :: <a href="#" title="Data.Int"
- >Int</a
- ></li
+ >foo</a
+ > :: ()</li
></ul
></details
></div
><div id="interface"
><a href="#" id="g:1"
><h1
- >Section1<a id="a:section1"
- ></a
- ></h1
- ></a
- ><div class="top"
- ><p class="src"
- ><a id="v:test1" class="def"
- >test1</a
- > :: <a href="#" title="Data.Int"
- >Int</a
- > <a href="#" class="selflink"
- >#</a
- ></p
- ></div
- ><a href="#" id="g:2"
- ><h1
- >Section2<a id="a:section2"
- ></a
- ></h1
+ >Header with <code
+ >foo</code
+ > link</h1
></a
><div class="top"
><p class="src"
- ><a id="v:test2" class="def"
- >test2</a
- > :: <a href="#" title="Data.Int"
- >Int</a
- > <a href="#" class="selflink"
+ ><a id="v:foo" class="def"
+ >foo</a
+ > :: () <a href="#" class="selflink"
>#</a
></p
></div
diff --git a/html-test/src/Bug1054.hs b/html-test/src/Bug1054.hs
new file mode 100644
index 00000000..c699f1fb
--- /dev/null
+++ b/html-test/src/Bug1054.hs
@@ -0,0 +1,5 @@
+module Bug1054 where
+
+-- * Header with 'foo' link
+
+foo = ()
diff --git a/html-test/src/Bug387.hs b/html-test/src/Bug387.hs
deleted file mode 100644
index d9fed34e..00000000
--- a/html-test/src/Bug387.hs
+++ /dev/null
@@ -1,12 +0,0 @@
-module Bug387
- ( -- * Section1#a:section1#
- test1
- -- * Section2#a:section2#
- , test2
- ) where
-
-test1 :: Int
-test1 = 223
-
-test2 :: Int
-test2 = 42