git.iko.soy/typeable/pandoc
on master help sign in
OpenDocument writer: treat image title of form "dddxddd" as size in px.

Later we'll modify the ODT writer to insert such titles, so image sizes will be correct in the ODT.

commit0299ae6c29e59674370dab884179045fef6b51f0 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 14 Jan 2012, 11:39 (15 years ago) parentd0582b9
1 file changed+14−3
src/Text/Pandoc/Writers/OpenDocument.hs+14−3
src/Text/Pandoc/Writers/OpenDocument.hs+14−3
@@ -40,7 +40,7 @@ import Text.Printf ( printf )
4040import Control.Applicative ( (<$>) )
4141import Control.Arrow ( (***), (>>>) )
4242import Control.Monad.State hiding ( when )
43−import Data.Char (chr)
43+import Data.Char (chr, isDigit)
4444import qualified Data.Map as Map
4545
4646-- | Auxiliary function to convert Plain block to Para.
@@ -378,7 +378,7 @@ inlineToOpenDocument o ils
378378 | RawInline "html" s <- ils = preformatted s -- for backwards compat.
379379 | RawInline _ _ <- ils = return empty
380380 | Link l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l
381− | Image _ (s,_) <- ils = return $ mkImg s
381+ | Image _ (s,t) <- ils = return $ mkImg s t
382382 | Note l <- ils = mkNote l
383383 | otherwise = return empty
384384 where
@@ -387,7 +387,7 @@ inlineToOpenDocument o ils
387387 , ("xlink:href" , s )
388388 , ("office:name", t )
389389 ] . inSpanTags "Definition"
390− mkImg s = inTags False "draw:frame" [] $
390+ mkImg s t = inTags False "draw:frame" (attrsFromTitle t) $
391391 selfClosingTag "draw:image" [ ("xlink:href" , s )
392392 , ("xlink:type" , "simple")
393393 , ("xlink:show" , "embed" )
@@ -403,6 +403,17 @@ inlineToOpenDocument o ils
403403 addNote nn
404404 return nn
405405
406+-- a title of the form "120x140" will be interpreted as image
407+-- size in pixels.
408+attrsFromTitle :: String -> [(String,String)]
409+attrsFromTitle s = if null xs || null ys
410+ then []
411+ else [("svg:x",xs),("svg:y",ys)]
412+ where (xs,rest) = span isDigit s
413+ ys = case rest of
414+ ('x':zs) | all isDigit zs -> zs
415+ _ -> ""
416+
406417bulletListStyle :: Int -> State WriterState (Int,(Int,[Doc]))
407418bulletListStyle l =
408419 let doStyles i = inTags True "text:list-level-style-bullet"