From 11385cf01f0d852782444ebfeb4e5092c174c6f8 Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Thu, 12 Jan 2012 21:28:14 +0100 Subject: Make sure that generated xhtml is valid (close #186) Thanks to Phyx. --- html/frames.html | 8 +++++--- src/Haddock/Backends/Xhtml.hs | 2 +- src/Haddock/Backends/Xhtml/Layout.hs | 9 +++++++++ src/Haddock/Backends/Xhtml/Utils.hs | 11 +---------- tests/html-tests/tests/A.html.ref | 2 +- tests/html-tests/tests/B.html.ref | 2 +- tests/html-tests/tests/Bug1.html.ref | 2 +- tests/html-tests/tests/Bug2.html.ref | 2 +- tests/html-tests/tests/Bug3.html.ref | 2 +- tests/html-tests/tests/Bug4.html.ref | 2 +- tests/html-tests/tests/Bug6.html.ref | 2 +- tests/html-tests/tests/Bug7.html.ref | 2 +- tests/html-tests/tests/Bug8.html.ref | 2 +- tests/html-tests/tests/Bugs.html.ref | 2 +- tests/html-tests/tests/CrossPackageDocs.html.ref | 2 +- tests/html-tests/tests/Examples.html.ref | 2 +- tests/html-tests/tests/FunArgs.html.ref | 2 +- tests/html-tests/tests/GADTRecords.html.ref | 2 +- tests/html-tests/tests/Hash.html.ref | 2 +- tests/html-tests/tests/NamedDoc.html.ref | 2 +- tests/html-tests/tests/NoLayout.html.ref | 2 +- tests/html-tests/tests/NonGreedy.html.ref | 2 +- tests/html-tests/tests/QuasiExpr.html.ref | 2 +- tests/html-tests/tests/QuasiQuote.html.ref | 2 +- tests/html-tests/tests/TH.html.ref | 2 +- tests/html-tests/tests/TH2.html.ref | 2 +- tests/html-tests/tests/Test.html.ref | 2 +- tests/html-tests/tests/Ticket112.html.ref | 2 +- tests/html-tests/tests/Ticket61.html.ref | 2 +- tests/html-tests/tests/Ticket75.html.ref | 2 +- tests/html-tests/tests/TypeFamilies.html.ref | 2 +- tests/html-tests/tests/TypeOperators.html.ref | 2 +- tests/html-tests/tests/Unicode.html.ref | 2 +- tests/html-tests/tests/Visible.html.ref | 2 +- 34 files changed, 46 insertions(+), 44 deletions(-) diff --git a/html/frames.html b/html/frames.html index 30ce1fa5..1b4e38d4 100644 --- a/html/frames.html +++ b/html/frames.html @@ -3,6 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> + + - - + + - + diff --git a/src/Haddock/Backends/Xhtml.hs b/src/Haddock/Backends/Xhtml.hs index 52bde5b6..c8998f3e 100644 --- a/src/Haddock/Backends/Xhtml.hs +++ b/src/Haddock/Backends/Xhtml.hs @@ -175,7 +175,7 @@ bodyHtml doctitle iface contentsButton maybe_contents_url, indexButton maybe_index_url]) ! [theclass "links", identifier "page-menu"], - nonEmpty sectionName << doctitle + nonEmptySectionName << doctitle ], divContent << pageContent, divFooter << paragraph << ( diff --git a/src/Haddock/Backends/Xhtml/Layout.hs b/src/Haddock/Backends/Xhtml/Layout.hs index bdd5ac78..da17552c 100644 --- a/src/Haddock/Backends/Xhtml/Layout.hs +++ b/src/Haddock/Backends/Xhtml/Layout.hs @@ -18,6 +18,7 @@ module Haddock.Backends.Xhtml.Layout ( divIndex, divAlphabet, divModuleList, sectionName, + nonEmptySectionName, shortDeclList, shortSubDecls, @@ -66,6 +67,14 @@ sectionName :: Html -> Html sectionName = paragraph ! [theclass "caption"] +-- | Make an element that always has at least something (a non-breaking space) +-- If it would have otherwise been empty, then give it the class ".empty" +nonEmptySectionName :: Html -> Html +nonEmptySectionName c + | isNoHtml c = paragraph ! [theclass "caption empty"] $ spaceHtml + | otherwise = paragraph ! [theclass "caption"] $ c + + divPackageHeader, divContent, divModuleHeader, divFooter, divTableOfContents, divDescription, divSynposis, divInterface, divIndex, divAlphabet, divModuleList diff --git a/src/Haddock/Backends/Xhtml/Utils.hs b/src/Haddock/Backends/Xhtml/Utils.hs index 7ba6d5f4..c020c64d 100644 --- a/src/Haddock/Backends/Xhtml/Utils.hs +++ b/src/Haddock/Backends/Xhtml/Utils.hs @@ -17,7 +17,7 @@ module Haddock.Backends.Xhtml.Utils ( spliceURL, groupId, - (<+>), char, nonEmpty, + (<+>), char, keyword, punctuate, braces, brackets, pabrackets, parens, parenList, ubxParenList, @@ -119,15 +119,6 @@ char :: Char -> Html char c = toHtml [c] --- | Make an element that always has at least something (a non-breaking space) --- If it would have otherwise been empty, then give it the class ".empty" -nonEmpty :: (Html -> Html) -> Html -> Html -nonEmpty el content_ = - if isNoHtml content_ - then el ! [theclass "empty"] << spaceHtml - else el << content_ - - quote :: Html -> Html quote h = char '`' +++ h +++ '`' diff --git a/tests/html-tests/tests/A.html.ref b/tests/html-tests/tests/A.html.ref index 38a39479..d5e6dcc0 100644 --- a/tests/html-tests/tests/A.html.ref +++ b/tests/html-tests/tests/A.html.ref @@ -25,7 +25,7 @@ window.onload = function () {pageLoad();setSynopsis("mini_A.html");}; >Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index

 

Index