git.iko.soy/typeable/pandoc
on master help sign in
Added distinction between tight and loose lists in OpenDocument writer.

(For bullet and enumerated lists only.) git-svn-id: https://pandoc.googlecode.com/svn/trunk@1305 788f1e2b-df1e-0410-8736-df70ead52e1b

commitbe719b2a44ecdc1278a81bd9716b1db1af53b2d7 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 13 Jul 2008, 16:31 (18 years ago) parent6bbe5d4
1 file changed+26−7
Text/Pandoc/Writers/OpenDocument.hs+26−7
Text/Pandoc/Writers/OpenDocument.hs+26−7
@@ -56,6 +56,7 @@ data WriterState =
5656 , stListStyles :: [(Int, [Doc])]
5757 , stIndentPara :: Int
5858 , stInDefinition :: Bool
59+ , stTight :: Bool
5960 }
6061
6162defaultWriterState :: WriterState
@@ -66,6 +67,7 @@ defaultWriterState =
6667 , stListStyles = []
6768 , stIndentPara = 0
6869 , stInDefinition = False
70+ , stTight = False
6971 }
7072
7173when :: Bool -> Doc -> Doc
@@ -86,6 +88,12 @@ increaseIndent = modify $ \s -> s { stIndentPara = 1 + stIndentPara s }
8688resetIndent :: State WriterState ()
8789resetIndent = modify $ \s -> s { stIndentPara = (stIndentPara s) - 1 }
8890
91+inTightList :: State WriterState a -> State WriterState a
92+inTightList f = do modify $ \s -> s { stTight = True }
93+ r <- f
94+ modify $ \s -> s { stTight = False }
95+ return r
96+
8997setInDefinitionList :: Bool -> State WriterState ()
9098setInDefinitionList b = modify $ \s -> s { stInDefinition = b }
9199
@@ -193,18 +201,24 @@ orderedItemToOpenDocument o n (b:bs)
193201 inTagsIndented "text:list" <$> orderedListToOpenDocument o nn l
194202orderedItemToOpenDocument _ _ [] = return empty
195203
196−newOrderedListStyle :: ListAttributes -> State WriterState (Int,Int)
197−newOrderedListStyle a = do
204+isTightList :: [[Block]] -> Bool
205+isTightList [] = False
206+isTightList (b:_)
207+ | Plain {} : _ <- b = True
208+ | otherwise = False
209+
210+newOrderedListStyle :: Bool -> ListAttributes -> State WriterState (Int,Int)
211+newOrderedListStyle b a = do
198212 ln <- (+) 1 . length <$> gets stListStyles
199− pn <- paraListStyle ln
200213 let nbs = orderedListLevelStyle a (ln, [])
214+ pn <- if b then inTightList (paraListStyle ln) else paraListStyle ln
201215 modify $ \s -> s { stListStyles = nbs : stListStyles s }
202216 return (ln,pn)
203217
204218bulletListToOpenDocument :: WriterOptions -> [[Block]] -> State WriterState Doc
205219bulletListToOpenDocument o b = do
206220 ln <- (+) 1 . length <$> gets stListStyles
207− (pn,ns) <- bulletListStyle ln
221+ (pn,ns) <- if isTightList b then inTightList (bulletListStyle ln) else bulletListStyle ln
208222 modify $ \s -> s { stListStyles = ns : stListStyles s }
209223 is <- listItemsToOpenDocument ("P" ++ show pn) o b
210224 return $ inTags True "text:list" [("text:style-name", "L" ++ show ln)] is
@@ -258,7 +272,7 @@ blockToOpenDocument o bs
258272 mkBlockQuote b = do increaseIndent
259273 i <- paraStyle "Quotations" []
260274 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
262276 inTags True "text:list" [ ("text:style-name", "L" ++ show ln)]
263277 <$> orderedListToOpenDocument o pn b
264278 table c a w h r = do
@@ -429,16 +443,21 @@ paraStyle parent attrs = do
429443 pn <- (+) 1 . length <$> gets stParaStyles
430444 i <- (*) 0.5 . fromIntegral <$> gets stIndentPara :: State WriterState Double
431445 b <- gets stInDefinition
446+ t <- gets stTight
432447 let styleAttr = [ ("style:name" , "P" ++ show pn)
433448 , ("style:family" , "paragraph" )
434449 , ("style:parent-style-name", parent )]
435450 indentVal = flip (++) "in" . show $ if b then (max 0.5 i) else i
436− indent = when (i /= 0 || b) $
437− selfClosingTag "style:paragraph-properties"
451+ tight = if t then [ ("fo:margin-top" , "0in" )
452+ , ("fo:margin-bottom" , "0in" )]
453+ else []
454+ indent = when (i /= 0 || b || t) $
455+ selfClosingTag "style:paragraph-properties" $
438456 [ ("fo:margin-left" , indentVal)
439457 , ("fo:margin-right" , "0in" )
440458 , ("fo:text-indent" , "0in" )
441459 , ("style:auto-text-indent" , "false" )]
460+ ++ tight
442461 addParaStyle $ inTags True "style:style" (styleAttr ++ attrs) indent
443462 return pn
444463