git.iko.soy/typeable/pandoc
on master help sign in
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

commitcc6294c4f271206609e41559d401288ad46e387e authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:17 (17 years ago) parent87537c3
3 files changed+40−51
src/Text/Pandoc/Writers/RTF.hs+20−34 templates/rtf.template+18−15 tests/writer.rtf+2−2
src/Text/Pandoc/Writers/RTF.hs+20−34
@@ -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
templates/rtf.template+18−15
@@ -1,22 +1,25 @@
1+$if(legacy-header)$
2+$legacy-header$
3+$else$
14{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
25{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
36\widowctrl\hyphauto
4−
7+$endif$
8+$for(header-includes)$
59$header-includes$
6−{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 {\i title}\par}
7−{\pard \qc \f0 \sa180 \li0 \fi0 $authors$\par}
10+$endfor$
11+
12+$if(title)$
13+{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 $title$\par}
14+$endif$
15+$for(author)$
16+{\pard \qc \f0 \sa180 \li0 \fi0 $author$\par}
17+$endfor$
18+$if(date)$
819{\pard \qc \f0 \sa180 \li0 \fi0 $date$\par}
20+$endif$
21+$if(spacer)$
922{\pard \ql \f0 \sa180 \li0 \fi0 \par}
10−{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Contents\par}
11−{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab section oen\sa180\par}
12−{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 section oen\par}
13−{\pard \ql \f0 \sa0 \li360 \fi-360 1.\tx360\tab one\par}
14−{\pard \ql \f0 \sa0 \li720 \fi-360 a.\tx360\tab two\par}
15−{\pard \ql \f0 \sa0 \li1080 \fi-360 iii.\tx360\tab three\sa180\sa180\sa180\par}
16−{\pard \ql \f0 \sa180 \li0 \fi0 \f1 hi\par}
17−{\pard \ql \f0 \sa180 \li0 \fi0 footnote{\super\chftn}{\*\footnote\chftn\~\plain\pard {\pard \ql \f0 \sa180 \li0 \fi0 with code\par}
18−{\pard \ql \f0 \sa180 \li0 \fi0 \f1 code\par}
19−}\par}
20−
23+$endif$
24+$body$
2125}
22−
tests/writer.rtf+2−2
@@ -3,7 +3,8 @@
33\widowctrl\hyphauto
44
55{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 Pandoc Test Suite\par}
6−{\pard \qc \f0 \sa180 \li0 \fi0 John MacFarlane\Anonymous\par}
6+{\pard \qc \f0 \sa180 \li0 \fi0 John MacFarlane\par}
7+{\pard \qc \f0 \sa180 \li0 \fi0 Anonymous\par}
78{\pard \qc \f0 \sa180 \li0 \fi0 July 17, 2006\par}
89{\pard \ql \f0 \sa180 \li0 \fi0 \par}
910{\pard \ql \f0 \sa180 \li0 \fi0 This is a set of tests for pandoc. Most of them are adapted from John Gruber\u8217's markdown test suite.\par}
@@ -448,6 +449,5 @@ links
448449{\pard \ql \f0 \sa0 \li360 \fi-360 1.\tx360\tab And in list items.{\super\chftn}{\*\footnote\chftn\~\plain\pard {\pard \ql \f0 \sa180 \li0 \fi0 In list.\par}
449450}\sa180\par}
450451{\pard \ql \f0 \sa180 \li0 \fi0 This paragraph should not be part of the note, as it is not indented.\par}
451−
452452}
453453