diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-03-20 17:14:18 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-03-20 17:14:18 +0000 |
commit | 1547728d7e5f91c383b4bdf82d69c78615500501 (patch) | |
tree | a702381e04a0d7eaed5af97966c0459dba89f213 | |
parent | bdd5ec37ae05785a7e0c13d537b960999a1c5a0c (diff) | |
download | pandoc-1547728d7e5f91c383b4bdf82d69c78615500501.tar.gz |
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
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 21 |
1 files changed, 11 insertions, 10 deletions
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 |