@@ -31,24 +31,31 @@ module Text.Pandoc.Writers.RTF ( writeRTF ) where
3131import Text.Pandoc.Definition
3232import Text.Pandoc.Shared
3333import Text.Pandoc.Readers.TeXMath
34+import Text.Pandoc.Templates (renderTemplate)
3435import Data.List ( isSuffixOf, intercalate )
3536import Data.Char ( ord, isDigit )
3637
3738-- | Convert Pandoc to a string in rich text format.
3839writeRTF :: WriterOptions -> Pandoc -> String
39−writeRTF options (Pandoc meta blocks) =
40− "" -- TODO
41−-- let head' = if writerStandalone options
42−-- then rtfHeader (writerHeader options) meta
43−-- else ""
44−-- toc = if writerTableOfContents options
45−-- then tableOfContents $ filter isHeaderBlock blocks
46−-- else ""
47−-- foot = if writerStandalone options then "\n}\n" else ""
48−-- body = writerIncludeBefore options ++
49−-- concatMap (blockToRTF 0 AlignDefault) blocks ++
50−-- writerIncludeAfter options
51−-- in head' ++ toc ++ body ++ foot
40+writeRTF options (Pandoc (Meta title authors date) blocks) =
41+ let titletext = inlineListToRTF title
42+ authorstext = map inlineListToRTF authors
43+ datetext = inlineListToRTF date
44+ spacer = not $ all null $ titletext : datetext : authorstext
45+ body = writerIncludeBefore options ++
46+ concatMap (blockToRTF 0 AlignDefault) blocks ++
47+ writerIncludeAfter options
48+ context = writerVariables options ++
49+ [ ("body", body)
50+ , ("title", titletext)
51+ , ("date", datetext) ] ++
52+ [ ("author", a) | a <- authorstext ] ++
53+ [ ("spacer", "yes") | spacer ] ++
54+ [ ("toc", tableOfContents $ filter isHeaderBlock blocks) |
55+ writerTableOfContents options ]
56+ in if writerStandalone options
57+ then renderTemplate context $ writerTemplate options
58+ else body
5259
5360-- | Construct table of contents from list of header blocks.
5461tableOfContents :: [Block] -> String
@@ -140,27 +147,6 @@ orderedMarkers indent (start, style, delim) =
140147 _ -> orderedListMarkers (start, LowerAlpha, Period)
141148 else orderedListMarkers (start, style, delim)
142149
143−-- | Returns RTF header.
144−rtfHeader :: String -- ^ header text
145− -> Meta -- ^ bibliographic information
146− -> String
147−rtfHeader headerText (Meta title authors date) =
148− let titletext = if null title
149− then ""
150− else rtfPar 0 0 AlignCenter $
151− "\\b \\fs36 " ++ inlineListToRTF title
152− authorstext = if null authors
153− then ""
154− else rtfPar 0 0 AlignCenter (" " ++ (intercalate "\\" $
155− map inlineListToRTF authors))
156− datetext = if null date
157− then ""
158− else rtfPar 0 0 AlignCenter (" " ++ inlineListToRTF date) in
159− let spacer = if null (titletext ++ authorstext ++ datetext)
160− then ""
161− else rtfPar 0 0 AlignDefault "" in
162− headerText ++ titletext ++ authorstext ++ datetext ++ spacer
163−
164150-- | Convert Pandoc block element to RTF.
165151blockToRTF :: Int -- ^ indent level
166152 -> Alignment -- ^ alignment