@@ -39,12 +39,30 @@ writeRTF :: WriterOptions -> Pandoc -> String
39writeRTF options (Pandoc meta blocks) =
39writeRTF options (Pandoc meta blocks) =
40 let head = if writerStandalone options
40 let head = if writerStandalone options
41 then rtfHeader (writerHeader options) meta
41 then rtfHeader (writerHeader options) meta
43+ toc = if writerTableOfContents options
44+ then tableOfContents $ filter isHeaderBlock blocks
43 foot = if writerStandalone options then "\n}\n" else ""
46 foot = if writerStandalone options then "\n}\n" else ""
44 body = (writerIncludeBefore options) ++
47 body = (writerIncludeBefore options) ++
45 concatMap (blockToRTF 0 AlignDefault) blocks ++
48 concatMap (blockToRTF 0 AlignDefault) blocks ++
46 (writerIncludeAfter options) in
49 (writerIncludeAfter options) in
47− head ++ body ++ foot
50+ head ++ toc ++ body ++ foot
52+-- | Construct table of contents from list of header blocks.
53+tableOfContents :: [Block] -> String
54+tableOfContents headers =
55+ let contentsTree = hierarchicalize headers
56+ in concatMap (blockToRTF 0 AlignDefault) $ [Header 1 [Str "Contents"],
57+ BulletList (map elementToListItem contentsTree)]
59+elementToListItem :: Element -> [Block]
60+elementToListItem (Blk _) = []
61+elementToListItem (Sec sectext subsecs) =
65+ else [BulletList (map elementToListItem subsecs)]
49-- | Convert unicode characters (> 127) into rich text format representation.
67-- | Convert unicode characters (> 127) into rich text format representation.
50handleUnicode :: String -> String
68handleUnicode :: String -> String