git.iko.soy/typeable/pandoc
on master help sign in
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

commit1547728d7e5f91c383b4bdf82d69c78615500501 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 20 Mar 2010, 17:14 (17 years ago) parentbdd5ec3
1 file changed+11−10
src/Text/Pandoc/Writers/HTML.hs+11−10
src/Text/Pandoc/Writers/HTML.hs+11−10
@@ -88,7 +88,7 @@ writeHtml opts d =
8888-- result is (title, authors, date, toc, body, new variables)
8989pandocToHtml :: WriterOptions
9090 -> Pandoc
91− -> State WriterState (Html, [Html], Html, Html, Html, [(String,String)])
91+ -> State WriterState (Html, [Html], Html, Maybe Html, Html, [(String,String)])
9292pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
9393 let standalone = writerStandalone opts
9494 tit <- if standalone
@@ -103,7 +103,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
103103 let sects = hierarchicalize blocks
104104 toc <- if writerTableOfContents opts
105105 then tableOfContents opts sects
106− else return noHtml
106+ else return Nothing
107107 blocks' <- liftM toHtmlFromList $ mapM (elementToHtml opts) sects
108108 st <- get
109109 let notes = reverse (stNotes st)
@@ -134,7 +134,7 @@ inTemplate :: TemplateTarget a
134134 -> Html
135135 -> [Html]
136136 -> Html
137− -> Html
137+ -> Maybe Html
138138 -> Html
139139 -> [(String,String)]
140140 -> a
@@ -147,9 +147,11 @@ inTemplate opts tit auths date toc body' newvars =
147147 context = variables ++
148148 [ ("body", renderHtmlFragment body')
149149 , ("pagetitle", topTitle')
150− , ("toc", renderHtmlFragment toc)
151150 , ("title", renderHtmlFragment tit)
152151 , ("date", date') ] ++
152+ (case toc of
153+ Just t -> [ ("toc", renderHtmlFragment t)]
154+ Nothing -> []) ++
153155 [ ("author", a) | a <- authors ]
154156 in renderTemplate context $ writerTemplate opts
155157
@@ -158,16 +160,15 @@ prefixedId :: WriterOptions -> String -> HtmlAttr
158160prefixedId opts s = identifier $ writerIdentifierPrefix opts ++ s
159161
160162-- | Construct table of contents from list of elements.
161−tableOfContents :: WriterOptions -> [Element] -> State WriterState Html
162−tableOfContents _ [] = return noHtml
163+tableOfContents :: WriterOptions -> [Element] -> State WriterState (Maybe Html)
164+tableOfContents _ [] = return Nothing
163165tableOfContents opts sects = do
164166 let opts' = opts { writerIgnoreNotes = True }
165167 contents <- mapM (elementToListItem opts') sects
166168 let tocList = catMaybes contents
167− return $ thediv ! [prefixedId opts' "TOC"] $
168− if null tocList
169− then noHtml
170− else unordList tocList
169+ return $ if null tocList
170+ then Nothing
171+ else Just $ thediv ! [prefixedId opts' "TOC"] $ unordList tocList
171172
172173-- | Convert section number to string
173174showSecNum :: [Int] -> String