git.iko.soy/typeable/pandoc
on master help sign in
Implemented --toc-depth for markdown writer.
commitea3eaaa55356d2f799c1ab5a96f9658e8ceaca97 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 5 Jan 2013, 12:31 (14 years ago) parent6666277
1 file changed+7−7
src/Text/Pandoc/Writers/Markdown.hs+7−7
src/Text/Pandoc/Writers/Markdown.hs+7−7
@@ -195,18 +195,18 @@ escapeString = escapeStringUsing markdownEscapes
195195tableOfContents :: WriterOptions -> [Block] -> Doc
196196tableOfContents opts headers =
197197 let opts' = opts { writerIgnoreNotes = True }
198− contents = BulletList $ map elementToListItem $ hierarchicalize headers
198+ contents = BulletList $ map (elementToListItem opts) $ hierarchicalize headers
199199 in evalState (blockToMarkdown opts' contents) WriterState{ stNotes = []
200200 , stRefs = []
201201 , stPlain = False }
202202
203203-- | Converts an Element to a list item for a table of contents,
204−elementToListItem :: Element -> [Block]
205−elementToListItem (Blk _) = []
206−elementToListItem (Sec _ _ _ headerText subsecs) = [Plain headerText] ++
207− if null subsecs
208− then []
209− else [BulletList $ map elementToListItem subsecs]
204+elementToListItem :: WriterOptions -> Element -> [Block]
205+elementToListItem opts (Sec lev _ _ headerText subsecs)
206+ = Plain headerText :
207+ [ BulletList (map (elementToListItem opts) subsecs) |
208+ not (null subsecs) && lev < writerTOCDepth opts ]
209+elementToListItem _ (Blk _) = []
210210
211211attrsToMarkdown :: Attr -> Doc
212212attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]