diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-09-17 11:41:05 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-09-17 11:41:05 -0700 |
commit | 4d49f76dbb8f51db5fd2527c3ef779996bf8936f (patch) | |
tree | 1169fee04e8c09b4c96580259c50d93cdf69d3c0 | |
parent | f2f35224f614199ac5fc26be84bba093a92ba984 (diff) | |
download | pandoc-4d49f76dbb8f51db5fd2527c3ef779996bf8936f.tar.gz |
Markdown writer: in TOC, add links to headers.
Closes #829.
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 804f4101d..5e7748efb 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -258,10 +258,13 @@ tableOfContents opts headers = -- | Converts an Element to a list item for a table of contents, elementToListItem :: WriterOptions -> Element -> [Block] -elementToListItem opts (Sec lev _ _ headerText subsecs) - = Plain headerText : +elementToListItem opts (Sec lev _nums (ident,_,_) headerText subsecs) + = Plain headerLink : [ BulletList (map (elementToListItem opts) subsecs) | not (null subsecs) && lev < writerTOCDepth opts ] + where headerLink = if null ident + then headerText + else [Link headerText ('#':ident, "")] elementToListItem _ (Blk _) = [] attrsToMarkdown :: Attr -> Doc |