Added support for --toc to RTF writer.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@657 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
parent
489a2bb1d9
commit
56efd6176f
1 changed files with 20 additions and 2 deletions
|
@ -39,12 +39,30 @@ writeRTF :: WriterOptions -> Pandoc -> String
|
||||||
writeRTF options (Pandoc meta blocks) =
|
writeRTF options (Pandoc meta blocks) =
|
||||||
let head = if writerStandalone options
|
let head = if writerStandalone options
|
||||||
then rtfHeader (writerHeader options) meta
|
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 ""
|
foot = if writerStandalone options then "\n}\n" else ""
|
||||||
body = (writerIncludeBefore options) ++
|
body = (writerIncludeBefore options) ++
|
||||||
concatMap (blockToRTF 0 AlignDefault) blocks ++
|
concatMap (blockToRTF 0 AlignDefault) blocks ++
|
||||||
(writerIncludeAfter options) in
|
(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.
|
-- | Convert unicode characters (> 127) into rich text format representation.
|
||||||
handleUnicode :: String -> String
|
handleUnicode :: String -> String
|
||||||
|
|
Loading…
Reference in a new issue