aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/RTF.hs54
1 files changed, 20 insertions, 34 deletions
diff --git a/src/Text/Pandoc/Writers/RTF.hs b/src/Text/Pandoc/Writers/RTF.hs
index 3830be705..9f3b9de2a 100644
--- a/src/Text/Pandoc/Writers/RTF.hs
+++ b/src/Text/Pandoc/Writers/RTF.hs
@@ -31,24 +31,31 @@ module Text.Pandoc.Writers.RTF ( writeRTF ) where
import Text.Pandoc.Definition
import Text.Pandoc.Shared
import Text.Pandoc.Readers.TeXMath
+import Text.Pandoc.Templates (renderTemplate)
import Data.List ( isSuffixOf, intercalate )
import Data.Char ( ord, isDigit )
-- | Convert Pandoc to a string in rich text format.
writeRTF :: WriterOptions -> Pandoc -> String
-writeRTF options (Pandoc meta blocks) =
- "" -- TODO
--- let head' = if writerStandalone options
--- then rtfHeader (writerHeader options) meta
--- 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' ++ toc ++ body ++ foot
+writeRTF options (Pandoc (Meta title authors date) blocks) =
+ let titletext = inlineListToRTF title
+ authorstext = map inlineListToRTF authors
+ datetext = inlineListToRTF date
+ spacer = not $ all null $ titletext : datetext : authorstext
+ body = writerIncludeBefore options ++
+ concatMap (blockToRTF 0 AlignDefault) blocks ++
+ writerIncludeAfter options
+ context = writerVariables options ++
+ [ ("body", body)
+ , ("title", titletext)
+ , ("date", datetext) ] ++
+ [ ("author", a) | a <- authorstext ] ++
+ [ ("spacer", "yes") | spacer ] ++
+ [ ("toc", tableOfContents $ filter isHeaderBlock blocks) |
+ writerTableOfContents options ]
+ in if writerStandalone options
+ then renderTemplate context $ writerTemplate options
+ else body
-- | Construct table of contents from list of header blocks.
tableOfContents :: [Block] -> String
@@ -140,27 +147,6 @@ orderedMarkers indent (start, style, delim) =
_ -> orderedListMarkers (start, LowerAlpha, Period)
else orderedListMarkers (start, style, delim)
--- | Returns RTF header.
-rtfHeader :: String -- ^ header text
- -> Meta -- ^ bibliographic information
- -> String
-rtfHeader headerText (Meta title authors date) =
- let titletext = if null title
- then ""
- else rtfPar 0 0 AlignCenter $
- "\\b \\fs36 " ++ inlineListToRTF title
- authorstext = if null authors
- then ""
- else rtfPar 0 0 AlignCenter (" " ++ (intercalate "\\" $
- map inlineListToRTF authors))
- datetext = if null date
- then ""
- else rtfPar 0 0 AlignCenter (" " ++ inlineListToRTF date) in
- let spacer = if null (titletext ++ authorstext ++ datetext)
- then ""
- else rtfPar 0 0 AlignDefault "" in
- headerText ++ titletext ++ authorstext ++ datetext ++ spacer
-
-- | Convert Pandoc block element to RTF.
blockToRTF :: Int -- ^ indent level
-> Alignment -- ^ alignment