@@ -31,24 +31,31 @@ module Text.Pandoc.Writers.RTF ( writeRTF ) where
31import Text.Pandoc.Definition
31import Text.Pandoc.Definition
32import Text.Pandoc.Shared
32import Text.Pandoc.Shared
33import Text.Pandoc.Readers.TeXMath
33import Text.Pandoc.Readers.TeXMath
34+import Text.Pandoc.Templates (renderTemplate)
34import Data.List ( isSuffixOf, intercalate )
35import Data.List ( isSuffixOf, intercalate )
35import Data.Char ( ord, isDigit )
36import Data.Char ( ord, isDigit )
37-- | Convert Pandoc to a string in rich text format.
38-- | Convert Pandoc to a string in rich text format.
38writeRTF :: WriterOptions -> Pandoc -> String
39writeRTF :: WriterOptions -> Pandoc -> String
39−writeRTF options (Pandoc meta blocks) =
40+writeRTF options (Pandoc (Meta title authors date) blocks) =
40− "" -- TODO
41+ let titletext = inlineListToRTF title
41−-- let head' = if writerStandalone options
42+ authorstext = map inlineListToRTF authors
42−-- then rtfHeader (writerHeader options) meta
43+ datetext = inlineListToRTF date
43−-- else ""
44+ spacer = not $ all null $ titletext : datetext : authorstext
44−-- toc = if writerTableOfContents options
45−-- then tableOfContents $ filter isHeaderBlock blocks
47−-- foot = if writerStandalone options then "\n}\n" else ""
48−-- body = writerIncludeBefore options ++
45+ body = writerIncludeBefore options ++
49−-- concatMap (blockToRTF 0 AlignDefault) blocks ++
46+ concatMap (blockToRTF 0 AlignDefault) blocks ++
50−-- writerIncludeAfter options
47+ writerIncludeAfter options
51−-- in head' ++ toc ++ body ++ foot
48+ context = writerVariables options ++
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
53-- | Construct table of contents from list of header blocks.
60-- | Construct table of contents from list of header blocks.
54tableOfContents :: [Block] -> String
61tableOfContents :: [Block] -> String
@@ -140,27 +147,6 @@ orderedMarkers indent (start, style, delim) =
140 _ -> orderedListMarkers (start, LowerAlpha, Period)
147 _ -> orderedListMarkers (start, LowerAlpha, Period)
141 else orderedListMarkers (start, style, delim)
148 else orderedListMarkers (start, style, delim)
143−-- | Returns RTF header.
144−rtfHeader :: String -- ^ header text
145− -> Meta -- ^ bibliographic information
147−rtfHeader headerText (Meta title authors date) =
148− let titletext = if null title
150− else rtfPar 0 0 AlignCenter $
151− "\\b \\fs36 " ++ inlineListToRTF title
152− authorstext = if null authors
154− else rtfPar 0 0 AlignCenter (" " ++ (intercalate "\\" $
155− map inlineListToRTF authors))
156− datetext = if null date
158− else rtfPar 0 0 AlignCenter (" " ++ inlineListToRTF date) in
159− let spacer = if null (titletext ++ authorstext ++ datetext)
161− else rtfPar 0 0 AlignDefault "" in
162− headerText ++ titletext ++ authorstext ++ datetext ++ spacer
164-- | Convert Pandoc block element to RTF.
150-- | Convert Pandoc block element to RTF.
165blockToRTF :: Int -- ^ indent level
151blockToRTF :: Int -- ^ indent level
166 -> Alignment -- ^ alignment
152 -> Alignment -- ^ alignment