From cc6294c4f271206609e41559d401288ad46e387e Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 31 Dec 2009 01:17:36 +0000 Subject: 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 --- src/Text/Pandoc/Writers/RTF.hs | 54 ++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) (limited to 'src/Text/Pandoc/Writers/RTF.hs') 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 -- cgit v1.2.3