@@ -1,7 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE PatternGuards #-}
33{-
4−Copyright (C) 2008 Andrea Rossato <andrea.rossato@unibz.it>
4+Copyright (C) 2008 Andrea Rossato <andrea.rossato@ing.unitn.it>
55
66This program is free software; you can redistribute it and/or modify
77it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2323 Copyright : Copyright (C) 2008 Andrea Rossato
2424 License : GNU GPL, version 2 or above
2525
26− Maintainer : Andrea Rossato <andrea.rossato@unibz.it>
26+ Maintainer : Andrea Rossato <andrea.rossato@ing.unitn.it>
2727 Stability : alpha
2828 Portability : portable
2929
@@ -50,12 +50,12 @@ plainToPara x = x
5050--
5151
5252data WriterState =
53− WriterState { stNotes :: [Doc]
54− , stTableStyles :: [Doc]
55− , stParaStyles :: [Doc]
53+ WriterState { stNotes :: [Doc]
54+ , stTableStyles :: [Doc]
55+ , stParaStyles :: [Doc]
5656 , stListStyles :: [(Int, [Doc])]
5757 , indentPara :: Int
58− } deriving Show
58+ }
5959
6060defaultWriterState :: WriterState
6161defaultWriterState =
@@ -222,7 +222,7 @@ blockToOpenDocument o bs
222222 | Plain b <- bs = wrap o b
223223 | Para b <- bs = inParagraphTags <$> wrap o b
224224 | Header i b <- bs = inHeaderTags i <$> wrap o b
225− | BlockQuote b <- bs = doBlockQuote b
225+ | BlockQuote b <- bs = mkBlockQuote b
226226 | CodeBlock _ s <- bs = preformatted s
227227 | RawHtml _ <- bs = return empty
228228 | DefinitionList b <- bs = defList b
@@ -235,7 +235,7 @@ blockToOpenDocument o bs
235235 where
236236 defList b = vcat <$> mapM (deflistItemToOpenDocument o) b
237237 preformatted s = vcat <$> mapM (inPreformattedTags . escapeStringForXML) (lines s)
238− doBlockQuote b = do increaseIndent
238+ mkBlockQuote b = do increaseIndent
239239 i <- paraStyle "Quotations" []
240240 inBlockQuote o i (map plainToPara b)
241241 orderedList a b = do (ln,pn) <- newOrderedListStyle a
@@ -275,7 +275,7 @@ tableRowToOpenDocument o tn ns cs =
275275
276276tableItemToOpenDocument :: WriterOptions -> String -> (String,[Block])-> State WriterState Doc
277277tableItemToOpenDocument o tn (n,i) =
278− let a = [ ("table:style-name" , tn ++ ".A1" )
278+ let a = [ ("table:style-name" , tn ++ ".A1" )
279279 , ("office:value-type", "string" )
280280 ]
281281 in inTags True "table:table-cell" a <$>
@@ -310,13 +310,13 @@ inlineToOpenDocument o ils
310310 | Code s <- ils = preformatted s
311311 | Math s <- ils = inlinesToOpenDocument o (readTeXMath s)
312312 | TeX s <- ils = preformatted s
313− | HtmlInline _ <- ils = return empty
313+ | HtmlInline s <- ils = preformatted s
314314 | Link l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l
315315 | Image l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l
316316 | Note l <- ils = mkNote l
317317 | otherwise = return empty
318318 where
319− preformatted = return . inSpanTags "Teletype" . text . escapeStringForXML
319+ preformatted = return . inSpanTags "Teletype" . text . escapeStringForXML
320320 mkLink s t = inTags False "text:a" [ ("xlink:type" , "simple")
321321 , ("xlink:href" , s )
322322 , ("office:name", t )
@@ -368,39 +368,45 @@ orderedListLevelStyle (s,n, d) (l,ls) =
368368 LowerRoman -> "i"
369369 _ -> "1"
370370 listStyle = inTags True "text:list-level-style-number"
371− ([ ("text:level" , show $ 1 + length ls )
371+ ([ ("text:level" , show $ 1 + length ls )
372372 , ("text:style-name" , "Numbering_20_Symbols")
373373 , ("style:num-format", format )
374− , ("text:start-value", show s )
374+ , ("text:start-value", show s )
375375 ] ++ suffix) (listLevelStyle (1 + length ls))
376376 in (l, ls ++ [listStyle])
377377
378378listLevelStyle :: Int -> Doc
379379listLevelStyle i =
380+ let indent = show (0.25 * fromIntegral i :: Double) in
380381 selfClosingTag "style:list-level-properties"
381− [ ("text:space-before" , show (0.25 * fromIntegral i :: Double) ++ "in")
382− , ("text:min-label-width","0.25in")]
382+ [ ("text:space-before" , indent ++ "in")
383+ , ("text:min-label-width", "0.25in")]
383384
384385tableStyle :: Int -> [(Char,Float)] -> Doc
385386tableStyle num wcs =
386387 let tableId = "Table" ++ show (num + 1)
387− table = inTags True "style:style" [("style:name", tableId)] $
388− selfClosingTag "style:table-properties" [ ("style:rel-width", "100%" )
389− , ("table:align" , "center")]
390− colStyle (c,w) = inTags True "style:style" [ ("style:name" , tableId ++ "." ++ [c])
391− , ("style:family", "table-column" )] $
392− selfClosingTag "style:table-column-properties" [("style:column-width", show (7 * w) ++ "in")]
393− cellStyle = inTags True "style:style" [ ("style:name" , tableId ++ ".A1")
394− , ("style:family", "table-cell" )] $
395− selfClosingTag "style:table-cell-properties" [ ("fo:border", "none")]
388+ table = inTags True "style:style"
389+ [("style:name", tableId)] $
390+ selfClosingTag "style:table-properties"
391+ [ ("style:rel-width", "100%" )
392+ , ("table:align" , "center")]
393+ colStyle (c,w) = inTags True "style:style"
394+ [ ("style:name" , tableId ++ "." ++ [c])
395+ , ("style:family", "table-column" )] $
396+ selfClosingTag "style:table-column-properties"
397+ [("style:column-width", show (7 * w) ++ "in")]
398+ cellStyle = inTags True "style:style"
399+ [ ("style:name" , tableId ++ ".A1")
400+ , ("style:family", "table-cell" )] $
401+ selfClosingTag "style:table-cell-properties"
402+ [ ("fo:border", "none")]
396403 columnStyles = map colStyle wcs
397−
398404 in table $$ vcat columnStyles $$ cellStyle
399405
400406paraStyle :: String -> [(String,String)] -> State WriterState Int
401407paraStyle parent attrs = do
402408 pn <- (+) 1 . length <$> gets stParaStyles
403− i <- (*) 0.5 . fromIntegral <$> gets indentPara :: State WriterState Double
409+ i <- (*) 0.5 . fromIntegral <$> gets indentPara :: State WriterState Double
404410 let styleAttr = [ ("style:name" , "P" ++ show pn)
405411 , ("style:family" , "paragraph" )
406412 , ("style:parent-style-name", parent )]
@@ -415,8 +421,7 @@ paraStyle parent attrs = do
415421 return pn
416422
417423paraListStyle :: Int -> State WriterState Int
418−paraListStyle l =
419− paraStyle "Text_20_body" [("style:list-style-name", "L" ++ show l )]
424+paraListStyle l = paraStyle "Text_20_body" [("style:list-style-name", "L" ++ show l )]
420425
421426paraTableStyles :: String -> Int -> [Alignment] -> [(String, Doc)]
422427paraTableStyles _ _ [] = []
@@ -428,12 +433,10 @@ paraTableStyles t s (a:xs)
428433 res sn x = inTags True "style:style"
429434 [ ("style:name" , pName sn )
430435 , ("style:family" , "paragraph" )
431− , ("style:parent-style-name", "Table_20_" ++ t)
432− ] $
436+ , ("style:parent-style-name", "Table_20_" ++ t)] $
433437 selfClosingTag "style:paragraph-properties"
434438 [ ("fo:text-align", x)
435− , ("style:justify-single-word", "false")
436− ]
439+ , ("style:justify-single-word", "false")]
437440
438441openDocumentNameSpaces :: [(String, String)]
439442openDocumentNameSpaces =