git.iko.soy/typeable/pandoc
on master help sign in
Implemented toc-depth for html writer.
08efc7dJohn MacFarlane
src/Text/Pandoc/Writers/HTML.hs+3−2
@@ -247,8 +247,8 @@ showSecNum = concat . intersperse "." . map show
247-- | Converts an Element to a list item for a table of contents,
247-- | Converts an Element to a list item for a table of contents,
248-- retrieving the appropriate identifier from state.
248-- retrieving the appropriate identifier from state.
249elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
249elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
250−elementToListItem _ (Blk _) = return Nothing
251−elementToListItem opts (Sec _ num id' headerText subsecs) = do
250+elementToListItem opts (Sec lev num id' headerText subsecs)
251+ | lev <= writerTOCDepth opts = do
252 let sectnum = if writerNumberSections opts
252 let sectnum = if writerNumberSections opts
253 then (H.span ! A.class_ "toc-section-number" $ toHtml $ showSecNum num) >>
253 then (H.span ! A.class_ "toc-section-number" $ toHtml $ showSecNum num) >>
254 preEscapedString " "
254 preEscapedString " "
@@ -260,6 +260,7 @@ elementToListItem opts (Sec _ num id' headerText subsecs) = do
260 else unordList opts subHeads
260 else unordList opts subHeads
261 return $ Just $ (H.a ! A.href (toValue $ "#" ++ writerIdentifierPrefix opts ++ id')
261 return $ Just $ (H.a ! A.href (toValue $ "#" ++ writerIdentifierPrefix opts ++ id')
262 $ toHtml txt) >> subList
262 $ toHtml txt) >> subList
263+elementToListItem _ _ = return Nothing
263
264
264-- | Convert an Element to Html.
265-- | Convert an Element to Html.
265elementToHtml :: Int -> WriterOptions -> Element -> State WriterState Html
266elementToHtml :: Int -> WriterOptions -> Element -> State WriterState Html