From 1547728d7e5f91c383b4bdf82d69c78615500501 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 20 Mar 2010 17:14:18 +0000 Subject: HTML writer: Don't include TOC div if table of contents is empty. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1922 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Writers/HTML.hs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index ddffa471b..9bc75296d 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -88,7 +88,7 @@ writeHtml opts d = -- result is (title, authors, date, toc, body, new variables) pandocToHtml :: WriterOptions -> Pandoc - -> State WriterState (Html, [Html], Html, Html, Html, [(String,String)]) + -> State WriterState (Html, [Html], Html, Maybe Html, Html, [(String,String)]) pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do let standalone = writerStandalone opts tit <- if standalone @@ -103,7 +103,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do let sects = hierarchicalize blocks toc <- if writerTableOfContents opts then tableOfContents opts sects - else return noHtml + else return Nothing blocks' <- liftM toHtmlFromList $ mapM (elementToHtml opts) sects st <- get let notes = reverse (stNotes st) @@ -134,7 +134,7 @@ inTemplate :: TemplateTarget a -> Html -> [Html] -> Html - -> Html + -> Maybe Html -> Html -> [(String,String)] -> a @@ -147,9 +147,11 @@ inTemplate opts tit auths date toc body' newvars = context = variables ++ [ ("body", renderHtmlFragment body') , ("pagetitle", topTitle') - , ("toc", renderHtmlFragment toc) , ("title", renderHtmlFragment tit) , ("date", date') ] ++ + (case toc of + Just t -> [ ("toc", renderHtmlFragment t)] + Nothing -> []) ++ [ ("author", a) | a <- authors ] in renderTemplate context $ writerTemplate opts @@ -158,16 +160,15 @@ prefixedId :: WriterOptions -> String -> HtmlAttr prefixedId opts s = identifier $ writerIdentifierPrefix opts ++ s -- | Construct table of contents from list of elements. -tableOfContents :: WriterOptions -> [Element] -> State WriterState Html -tableOfContents _ [] = return noHtml +tableOfContents :: WriterOptions -> [Element] -> State WriterState (Maybe Html) +tableOfContents _ [] = return Nothing tableOfContents opts sects = do let opts' = opts { writerIgnoreNotes = True } contents <- mapM (elementToListItem opts') sects let tocList = catMaybes contents - return $ thediv ! [prefixedId opts' "TOC"] $ - if null tocList - then noHtml - else unordList tocList + return $ if null tocList + then Nothing + else Just $ thediv ! [prefixedId opts' "TOC"] $ unordList tocList -- | Convert section number to string showSecNum :: [Int] -> String -- cgit v1.2.3