aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-05 12:31:15 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-05 12:31:15 -0800
commitea3eaaa55356d2f799c1ab5a96f9658e8ceaca97 (patch)
treec567fed098a701dbdc23d71d7ac47953cc5c6fb8 /src/Text
parent6666277fa23d2c6a5d747ebf42bd7cd2a2e7c126 (diff)
downloadpandoc-ea3eaaa55356d2f799c1ab5a96f9658e8ceaca97.tar.gz
Implemented --toc-depth for markdown writer.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 9bc7cab6a..234a9cc76 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -195,18 +195,18 @@ escapeString = escapeStringUsing markdownEscapes
tableOfContents :: WriterOptions -> [Block] -> Doc
tableOfContents opts headers =
let opts' = opts { writerIgnoreNotes = True }
- contents = BulletList $ map elementToListItem $ hierarchicalize headers
+ contents = BulletList $ map (elementToListItem opts) $ hierarchicalize headers
in evalState (blockToMarkdown opts' contents) WriterState{ stNotes = []
, stRefs = []
, stPlain = False }
-- | Converts an Element to a list item for a table of contents,
-elementToListItem :: Element -> [Block]
-elementToListItem (Blk _) = []
-elementToListItem (Sec _ _ _ headerText subsecs) = [Plain headerText] ++
- if null subsecs
- then []
- else [BulletList $ map elementToListItem subsecs]
+elementToListItem :: WriterOptions -> Element -> [Block]
+elementToListItem opts (Sec lev _ _ headerText subsecs)
+ = Plain headerText :
+ [ BulletList (map (elementToListItem opts) subsecs) |
+ not (null subsecs) && lev < writerTOCDepth opts ]
+elementToListItem _ (Blk _) = []
attrsToMarkdown :: Attr -> Doc
attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]