@@ -56,6 +56,7 @@ data WriterState =
56 , stListStyles :: [(Int, [Doc])]
56 , stListStyles :: [(Int, [Doc])]
57 , stIndentPara :: Int
57 , stIndentPara :: Int
58 , stInDefinition :: Bool
58 , stInDefinition :: Bool
61defaultWriterState :: WriterState
62defaultWriterState :: WriterState
@@ -66,6 +67,7 @@ defaultWriterState =
66 , stListStyles = []
67 , stListStyles = []
67 , stIndentPara = 0
68 , stIndentPara = 0
68 , stInDefinition = False
69 , stInDefinition = False
71when :: Bool -> Doc -> Doc
73when :: Bool -> Doc -> Doc
@@ -86,6 +88,12 @@ increaseIndent = modify $ \s -> s { stIndentPara = 1 + stIndentPara s }
86resetIndent :: State WriterState ()
88resetIndent :: State WriterState ()
87resetIndent = modify $ \s -> s { stIndentPara = (stIndentPara s) - 1 }
89resetIndent = modify $ \s -> s { stIndentPara = (stIndentPara s) - 1 }
91+inTightList :: State WriterState a -> State WriterState a
92+inTightList f = do modify $ \s -> s { stTight = True }
94+ modify $ \s -> s { stTight = False }
89setInDefinitionList :: Bool -> State WriterState ()
97setInDefinitionList :: Bool -> State WriterState ()
90setInDefinitionList b = modify $ \s -> s { stInDefinition = b }
98setInDefinitionList b = modify $ \s -> s { stInDefinition = b }
@@ -193,18 +201,24 @@ orderedItemToOpenDocument o n (b:bs)
193 inTagsIndented "text:list" <$> orderedListToOpenDocument o nn l
201 inTagsIndented "text:list" <$> orderedListToOpenDocument o nn l
194orderedItemToOpenDocument _ _ [] = return empty
202orderedItemToOpenDocument _ _ [] = return empty
204+isTightList :: [[Block]] -> Bool
205+isTightList [] = False
207+ | Plain {} : _ <- b = True
196−newOrderedListStyle :: ListAttributes -> State WriterState (Int,Int)
210+newOrderedListStyle :: Bool -> ListAttributes -> State WriterState (Int,Int)
197−newOrderedListStyle a = do
211+newOrderedListStyle b a = do
198 ln <- (+) 1 . length <$> gets stListStyles
212 ln <- (+) 1 . length <$> gets stListStyles
199− pn <- paraListStyle ln
200 let nbs = orderedListLevelStyle a (ln, [])
213 let nbs = orderedListLevelStyle a (ln, [])
214+ pn <- if b then inTightList (paraListStyle ln) else paraListStyle ln
201 modify $ \s -> s { stListStyles = nbs : stListStyles s }
215 modify $ \s -> s { stListStyles = nbs : stListStyles s }
202 return (ln,pn)
216 return (ln,pn)
204bulletListToOpenDocument :: WriterOptions -> [[Block]] -> State WriterState Doc
218bulletListToOpenDocument :: WriterOptions -> [[Block]] -> State WriterState Doc
205bulletListToOpenDocument o b = do
219bulletListToOpenDocument o b = do
206 ln <- (+) 1 . length <$> gets stListStyles
220 ln <- (+) 1 . length <$> gets stListStyles
207− (pn,ns) <- bulletListStyle ln
221+ (pn,ns) <- if isTightList b then inTightList (bulletListStyle ln) else bulletListStyle ln
208 modify $ \s -> s { stListStyles = ns : stListStyles s }
222 modify $ \s -> s { stListStyles = ns : stListStyles s }
209 is <- listItemsToOpenDocument ("P" ++ show pn) o b
223 is <- listItemsToOpenDocument ("P" ++ show pn) o b
210 return $ inTags True "text:list" [("text:style-name", "L" ++ show ln)] is
224 return $ inTags True "text:list" [("text:style-name", "L" ++ show ln)] is
@@ -258,7 +272,7 @@ blockToOpenDocument o bs
258 mkBlockQuote b = do increaseIndent
272 mkBlockQuote b = do increaseIndent
259 i <- paraStyle "Quotations" []
273 i <- paraStyle "Quotations" []
260 inBlockQuote o i (map plainToPara b)
274 inBlockQuote o i (map plainToPara b)
261− orderedList a b = do (ln,pn) <- newOrderedListStyle a
275+ orderedList a b = do (ln,pn) <- newOrderedListStyle (isTightList b) a
262 inTags True "text:list" [ ("text:style-name", "L" ++ show ln)]
276 inTags True "text:list" [ ("text:style-name", "L" ++ show ln)]
263 <$> orderedListToOpenDocument o pn b
277 <$> orderedListToOpenDocument o pn b
264 table c a w h r = do
278 table c a w h r = do
@@ -429,16 +443,21 @@ paraStyle parent attrs = do
429 pn <- (+) 1 . length <$> gets stParaStyles
443 pn <- (+) 1 . length <$> gets stParaStyles
430 i <- (*) 0.5 . fromIntegral <$> gets stIndentPara :: State WriterState Double
444 i <- (*) 0.5 . fromIntegral <$> gets stIndentPara :: State WriterState Double
431 b <- gets stInDefinition
445 b <- gets stInDefinition
432 let styleAttr = [ ("style:name" , "P" ++ show pn)
447 let styleAttr = [ ("style:name" , "P" ++ show pn)
433 , ("style:family" , "paragraph" )
448 , ("style:family" , "paragraph" )
434 , ("style:parent-style-name", parent )]
449 , ("style:parent-style-name", parent )]
435 indentVal = flip (++) "in" . show $ if b then (max 0.5 i) else i
450 indentVal = flip (++) "in" . show $ if b then (max 0.5 i) else i
451+ tight = if t then [ ("fo:margin-top" , "0in" )
452+ , ("fo:margin-bottom" , "0in" )]
436− indent = when (i /= 0 || b) $
454+ indent = when (i /= 0 || b || t) $
437− selfClosingTag "style:paragraph-properties"
455+ selfClosingTag "style:paragraph-properties" $
438 [ ("fo:margin-left" , indentVal)
456 [ ("fo:margin-left" , indentVal)
439 , ("fo:margin-right" , "0in" )
457 , ("fo:margin-right" , "0in" )
440 , ("fo:text-indent" , "0in" )
458 , ("fo:text-indent" , "0in" )
441 , ("style:auto-text-indent" , "false" )]
459 , ("style:auto-text-indent" , "false" )]
442 addParaStyle $ inTags True "style:style" (styleAttr ++ attrs) indent
461 addParaStyle $ inTags True "style:style" (styleAttr ++ attrs) indent
443 return pn
462 return pn