git.iko.soy/typeable/pandoc
on master help sign in
Code cleanup in RTF writer.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1313 788f1e2b-df1e-0410-8736-df70ead52e1b

commit45a734878e50c94c2b85c1090f986fad3e94e160 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 13 Jul 2008, 23:25 (18 years ago) parentff43ff6
1 file changed+17−18
Text/Pandoc/Writers/RTF.hs+17−18
Text/Pandoc/Writers/RTF.hs+17−18
@@ -37,9 +37,9 @@ import Data.Char ( ord, isDigit )
3737-- | Convert Pandoc to a string in rich text format.
3838writeRTF :: WriterOptions -> Pandoc -> String
3939writeRTF options (Pandoc meta blocks) =
40− let head = if writerStandalone options
41− then rtfHeader (writerHeader options) meta
42− else ""
40+ let head' = if writerStandalone options
41+ then rtfHeader (writerHeader options) meta
42+ else ""
4343 toc = if writerTableOfContents options
4444 then tableOfContents $ filter isHeaderBlock blocks
4545 else ""
@@ -47,7 +47,7 @@ writeRTF options (Pandoc meta blocks) =
4747 body = writerIncludeBefore options ++
4848 concatMap (blockToRTF 0 AlignDefault) blocks ++
4949 writerIncludeAfter options
50− in head ++ toc ++ body ++ foot
50+ in head' ++ toc ++ body ++ foot
5151
5252-- | Construct table of contents from list of header blocks.
5353tableOfContents :: [Block] -> String
@@ -84,10 +84,6 @@ stringToRTF = handleUnicode . escapeSpecial
8484codeStringToRTF :: String -> String
8585codeStringToRTF str = joinWithSep "\\line\n" $ lines (stringToRTF str)
8686
87−-- | Deal with raw LaTeX.
88−latexToRTF :: String -> String
89−latexToRTF str = "{\\cf1 " ++ (stringToRTF str) ++ "\\cf0 }"
90−
9187-- | Make a paragraph with first-line indent, block indent, and space after.
9288rtfParSpaced :: Int -- ^ space after (in twips)
9389 -> Int -- ^ block indent (in twips)
@@ -122,22 +118,25 @@ rtfCompact :: Int -- ^ block indent (in twips)
122118rtfCompact = rtfParSpaced 0
123119
124120-- number of twips to indent
121+indentIncrement :: Int
125122indentIncrement = 720
123+
124+listIncrement :: Int
126125listIncrement = 360
127126
128127-- | Returns appropriate bullet list marker for indent level.
129128bulletMarker :: Int -> String
130129bulletMarker indent = case indent `mod` 720 of
131− 0 -> "\\bullet "
132− otherwise -> "\\endash "
130+ 0 -> "\\bullet "
131+ _ -> "\\endash "
133132
134133-- | Returns appropriate (list of) ordered list markers for indent level.
135134orderedMarkers :: Int -> ListAttributes -> [String]
136135orderedMarkers indent (start, style, delim) =
137136 if style == DefaultStyle && delim == DefaultDelim
138137 then case indent `mod` 720 of
139− 0 -> orderedListMarkers (start, Decimal, Period)
140− otherwise -> orderedListMarkers (start, LowerAlpha, Period)
138+ 0 -> orderedListMarkers (start, Decimal, Period)
139+ _ -> orderedListMarkers (start, LowerAlpha, Period)
141140 else orderedListMarkers (start, style, delim)
142141
143142-- | Returns RTF header.
@@ -175,7 +174,7 @@ blockToRTF indent alignment (BlockQuote lst) =
175174 concatMap (blockToRTF (indent + indentIncrement) alignment) lst
176175blockToRTF indent _ (CodeBlock _ str) =
177176 rtfPar indent 0 AlignLeft ("\\f1 " ++ (codeStringToRTF str))
178−blockToRTF _ _ (RawHtml str) = ""
177+blockToRTF _ _ (RawHtml _) = ""
179178blockToRTF indent alignment (BulletList lst) = spaceAtEnd $
180179 concatMap (listItemToRTF alignment indent (bulletMarker indent)) lst
181180blockToRTF indent alignment (OrderedList attribs lst) = spaceAtEnd $ concat $
@@ -238,7 +237,7 @@ listItemToRTF alignment indent marker list =
238237 listMarker ++ dropWhile isDigit xs
239238 insertListMarker (x:xs) =
240239 x : insertListMarker xs
241− insertListmarker [] = []
240+ insertListMarker [] = []
242241 -- insert the list marker into the (processed) first block
243242 in insertListMarker first ++ concat rest
244243
@@ -276,14 +275,14 @@ inlineToRTF EnDash = "\\u8211-"
276275inlineToRTF (Code str) = "{\\f1 " ++ (codeStringToRTF str) ++ "}"
277276inlineToRTF (Str str) = stringToRTF str
278277inlineToRTF (Math str) = inlineListToRTF $ readTeXMath str
279−inlineToRTF (TeX str) = ""
280−inlineToRTF (HtmlInline str) = ""
278+inlineToRTF (TeX _) = ""
279+inlineToRTF (HtmlInline _) = ""
281280inlineToRTF (LineBreak) = "\\line "
282281inlineToRTF Space = " "
283−inlineToRTF (Link text (src, tit)) =
282+inlineToRTF (Link text (src, _)) =
284283 "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
285284 "\"}}{\\fldrslt{\\ul\n" ++ (inlineListToRTF text) ++ "\n}}}\n"
286−inlineToRTF (Image alternate (source, tit)) =
285+inlineToRTF (Image _ (source, _)) =
287286 "{\\cf1 [image: " ++ source ++ "]\\cf0}"
288287inlineToRTF (Note contents) =
289288 "{\\super\\chftn}{\\*\\footnote\\chftn\\~\\plain\\pard " ++