summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:17:36 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:17:36 +0000
commitcc6294c4f271206609e41559d401288ad46e387e (patch)
tree8d272aad2043dd701e77c7d5e60299e62fa004b0 /src/Text/Pandoc
parent87537c3ff829d7cbcd56d34d03da7ce559e2898d (diff)
Modified RTF writer to use new templates.
Also changed treatment of multiple authors: they now occupy multiple paragraphs rather than using a line break. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1734 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc')
-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