git.iko.soy/typeable/pandoc
on master help sign in
Modified RTF writer to use new templates.
cc6294cfiddlosopher
src/Text/Pandoc/Writers/RTF.hs+20−34
@@ -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 )
36
37
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
46−-- else ""
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 ++
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
52
59
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)
142
149
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−
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
templates/rtf.template+18−15
@@ -1,22 +1,25 @@
1+$if(legacy-header)$
2+$legacy-header$
3+$else$
1{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
4{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
2{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
5{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
3\widowctrl\hyphauto
6\widowctrl\hyphauto
4−
7+$endif$
8+$for(header-includes)$
5$header-includes$
9$header-includes$
10+$endfor$
11+
12+$if(title)$
6−{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 {\i title}\par}
13+{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 $title$\par}
14+$endif$
15+$for(author)$
7−{\pard \qc \f0 \sa180 \li0 \fi0 $authors$\par}
16+{\pard \qc \f0 \sa180 \li0 \fi0 $author$\par}
17+$endfor$
18+$if(date)$
8{\pard \qc \f0 \sa180 \li0 \fi0 $date$\par}
19{\pard \qc \f0 \sa180 \li0 \fi0 $date$\par}
20+$endif$
21+$if(spacer)$
9{\pard \ql \f0 \sa180 \li0 \fi0 \par}
22{\pard \ql \f0 \sa180 \li0 \fi0 \par}
10−{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Contents\par}
23+$endif$
11−{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab section oen\sa180\par}
24+$body$
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−
21}
25}
22−
tests/writer.rtf+2−2
@@ -3,7 +3,8 @@
3\widowctrl\hyphauto
3\widowctrl\hyphauto
4
4
5{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 Pandoc Test Suite\par}
5{\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}
7{\pard \qc \f0 \sa180 \li0 \fi0 July 17, 2006\par}
8{\pard \qc \f0 \sa180 \li0 \fi0 July 17, 2006\par}
8{\pard \ql \f0 \sa180 \li0 \fi0 \par}
9{\pard \ql \f0 \sa180 \li0 \fi0 \par}
9{\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}
10{\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
448{\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}
449{\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}
449}\sa180\par}
450}\sa180\par}
450{\pard \ql \f0 \sa180 \li0 \fi0 This paragraph should not be part of the note, as it is not indented.\par}
451{\pard \ql \f0 \sa180 \li0 \fi0 This paragraph should not be part of the note, as it is not indented.\par}
451−
452}
452}
453
453