@@ -88,7 +88,7 @@ writeHtml opts d =
88-- result is (title, authors, date, toc, body, new variables)
88-- result is (title, authors, date, toc, body, new variables)
89pandocToHtml :: WriterOptions
89pandocToHtml :: WriterOptions
91− -> State WriterState (Html, [Html], Html, Html, Html, [(String,String)])
91+ -> State WriterState (Html, [Html], Html, Maybe Html, Html, [(String,String)])
92pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
92pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
93 let standalone = writerStandalone opts
93 let standalone = writerStandalone opts
94 tit <- if standalone
94 tit <- if standalone
@@ -103,7 +103,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
103 let sects = hierarchicalize blocks
103 let sects = hierarchicalize blocks
104 toc <- if writerTableOfContents opts
104 toc <- if writerTableOfContents opts
105 then tableOfContents opts sects
105 then tableOfContents opts sects
106− else return noHtml
106+ else return Nothing
107 blocks' <- liftM toHtmlFromList $ mapM (elementToHtml opts) sects
107 blocks' <- liftM toHtmlFromList $ mapM (elementToHtml opts) sects
108 st <- get
108 st <- get
109 let notes = reverse (stNotes st)
109 let notes = reverse (stNotes st)
@@ -134,7 +134,7 @@ inTemplate :: TemplateTarget a
135 -> [Html]
135 -> [Html]
137− -> Html
137+ -> Maybe Html
139 -> [(String,String)]
139 -> [(String,String)]
@@ -147,9 +147,11 @@ inTemplate opts tit auths date toc body' newvars =
147 context = variables ++
147 context = variables ++
148 [ ("body", renderHtmlFragment body')
148 [ ("body", renderHtmlFragment body')
149 , ("pagetitle", topTitle')
149 , ("pagetitle", topTitle')
150− , ("toc", renderHtmlFragment toc)
151 , ("title", renderHtmlFragment tit)
150 , ("title", renderHtmlFragment tit)
152 , ("date", date') ] ++
151 , ("date", date') ] ++
153+ Just t -> [ ("toc", renderHtmlFragment t)]
153 [ ("author", a) | a <- authors ]
155 [ ("author", a) | a <- authors ]
154 in renderTemplate context $ writerTemplate opts
156 in renderTemplate context $ writerTemplate opts
@@ -158,16 +160,15 @@ prefixedId :: WriterOptions -> String -> HtmlAttr
158prefixedId opts s = identifier $ writerIdentifierPrefix opts ++ s
160prefixedId opts s = identifier $ writerIdentifierPrefix opts ++ s
160-- | Construct table of contents from list of elements.
162-- | Construct table of contents from list of elements.
161−tableOfContents :: WriterOptions -> [Element] -> State WriterState Html
163+tableOfContents :: WriterOptions -> [Element] -> State WriterState (Maybe Html)
162−tableOfContents _ [] = return noHtml
164+tableOfContents _ [] = return Nothing
163tableOfContents opts sects = do
165tableOfContents opts sects = do
164 let opts' = opts { writerIgnoreNotes = True }
166 let opts' = opts { writerIgnoreNotes = True }
165 contents <- mapM (elementToListItem opts') sects
167 contents <- mapM (elementToListItem opts') sects
166 let tocList = catMaybes contents
168 let tocList = catMaybes contents
169+ return $ if null tocList
167− return $ thediv ! [prefixedId opts' "TOC"] $
171+ else Just $ thediv ! [prefixedId opts' "TOC"] $ unordList tocList
170− else unordList tocList
172-- | Convert section number to string
173-- | Convert section number to string
173showSecNum :: [Int] -> String
174showSecNum :: [Int] -> String