git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: write image width specified in percent in Text::Amuse mode
d777fe8Alexander Krotov
src/Text/Pandoc/Writers/Muse.hs+7−2
@@ -48,6 +48,7 @@ import Data.List (intersperse, transpose, isInfixOf)
48import System.FilePath (takeExtension)
48import System.FilePath (takeExtension)
49import Text.Pandoc.Class (PandocMonad)
49import Text.Pandoc.Class (PandocMonad)
50import Text.Pandoc.Definition
50import Text.Pandoc.Definition
51+import Text.Pandoc.ImageSize
51import Text.Pandoc.Options
52import Text.Pandoc.Options
52import Text.Pandoc.Pretty
53import Text.Pandoc.Pretty
53import Text.Pandoc.Shared
54import Text.Pandoc.Shared
@@ -384,14 +385,18 @@ inlineToMuse (Link _ txt (src, _)) =
384 isImageUrl = (`elem` imageExtensions) . takeExtension
385 isImageUrl = (`elem` imageExtensions) . takeExtension
385inlineToMuse (Image attr alt (source,'f':'i':'g':':':title)) =
386inlineToMuse (Image attr alt (source,'f':'i':'g':':':title)) =
386 inlineToMuse (Image attr alt (source,title))
387 inlineToMuse (Image attr alt (source,title))
387−inlineToMuse (Image _ inlines (source, title)) = do
388+inlineToMuse (Image attr inlines (source, title)) = do
389+ opts <- gets stOptions
388 alt <- inlineListToMuse inlines
390 alt <- inlineListToMuse inlines
389 let title' = if null title
391 let title' = if null title
390 then if null inlines
392 then if null inlines
391 then ""
393 then ""
392 else "[" <> alt <> "]"
394 else "[" <> alt <> "]"
393 else "[" <> text title <> "]"
395 else "[" <> text title <> "]"
396+ let width = case dimension Width attr of
397+ Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
398+ _ -> ""
394− return $ "[[" <> text source <> "]" <> title' <> "]"
399+ return $ "[[" <> text (source ++ width) <> "]" <> title' <> "]"
395inlineToMuse (Note contents) = do
400inlineToMuse (Note contents) = do
396 -- add to notes in state
401 -- add to notes in state
397 notes <- gets stNotes
402 notes <- gets stNotes
test/Tests/Writers/Muse.hs+3
@@ -351,6 +351,9 @@ tests = [ testGroup "block elements"
351 =?> "[[URL:1.png]]"
351 =?> "[[URL:1.png]]"
352 ]
352 ]
353 , "image" =: image "image.png" "Image 1" (str "") =?> "[[image.png][Image 1]]"
353 , "image" =: image "image.png" "Image 1" (str "") =?> "[[image.png][Image 1]]"
354+ , "image with width" =:
355+ imageWith ("", [], [("width", "60%")]) "image.png" "Image" (str "") =?>
356+ "[[image.png 60][Image]]"
354 , "note" =: note (plain (text "Foo"))
357 , "note" =: note (plain (text "Foo"))
355 =?> unlines [ "[1]"
358 =?> unlines [ "[1]"
356 , ""
359 , ""