aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-09-17 11:41:05 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-09-17 11:41:05 -0700
commit4d49f76dbb8f51db5fd2527c3ef779996bf8936f (patch)
tree1169fee04e8c09b4c96580259c50d93cdf69d3c0 /src/Text/Pandoc/Writers
parentf2f35224f614199ac5fc26be84bba093a92ba984 (diff)
downloadpandoc-4d49f76dbb8f51db5fd2527c3ef779996bf8936f.tar.gz
Markdown writer: in TOC, add links to headers.
Closes #829.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs7
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