aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-07-09 00:51:07 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-07-09 00:51:07 +0000
commit56efd6176f0b9ed4df366116e69c3712fdfa36db (patch)
tree56bd9f163f6dfc0cdfcbdee1b961dadcbd14653c /src
parent489a2bb1d9d9f8473f5e11cb6c74b5c6f5e9c866 (diff)
downloadpandoc-56efd6176f0b9ed4df366116e69c3712fdfa36db.tar.gz
Added support for --toc to RTF writer.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@657 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/RTF.hs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/RTF.hs b/src/Text/Pandoc/Writers/RTF.hs
index 9adc2a980..229de12a3 100644
--- a/src/Text/Pandoc/Writers/RTF.hs
+++ b/src/Text/Pandoc/Writers/RTF.hs
@@ -39,12 +39,30 @@ writeRTF :: WriterOptions -> Pandoc -> String
writeRTF options (Pandoc meta blocks) =
let head = if writerStandalone options
then rtfHeader (writerHeader options) meta
- else ""
+ else ""
+ toc = if writerTableOfContents options
+ then tableOfContents $ filter isHeaderBlock blocks
+ else ""
foot = if writerStandalone options then "\n}\n" else ""
body = (writerIncludeBefore options) ++
concatMap (blockToRTF 0 AlignDefault) blocks ++
(writerIncludeAfter options) in
- head ++ body ++ foot
+ head ++ toc ++ body ++ foot
+
+-- | Construct table of contents from list of header blocks.
+tableOfContents :: [Block] -> String
+tableOfContents headers =
+ let contentsTree = hierarchicalize headers
+ in concatMap (blockToRTF 0 AlignDefault) $ [Header 1 [Str "Contents"],
+ BulletList (map elementToListItem contentsTree)]
+
+elementToListItem :: Element -> [Block]
+elementToListItem (Blk _) = []
+elementToListItem (Sec sectext subsecs) =
+ [Plain sectext] ++
+ if null subsecs
+ then []
+ else [BulletList (map elementToListItem subsecs)]
-- | Convert unicode characters (> 127) into rich text format representation.
handleUnicode :: String -> String