git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: write image width specified in percent in Text::Amuse mode
commitd777fe8bbecc3320cf95754dbe7f9eee21876770 authorAlexander Krotov <ilabdsf@gmail.com> dateSat 3 Feb 2018, 18:36 (9 years ago) parenteeafb3f
2 files changed+10−2
src/Text/Pandoc/Writers/Muse.hs+7−2 test/Tests/Writers/Muse.hs+3
src/Text/Pandoc/Writers/Muse.hs+7−2
@@ -48,6 +48,7 @@ import Data.List (intersperse, transpose, isInfixOf)
4848import System.FilePath (takeExtension)
4949import Text.Pandoc.Class (PandocMonad)
5050import Text.Pandoc.Definition
51+import Text.Pandoc.ImageSize
5152import Text.Pandoc.Options
5253import Text.Pandoc.Pretty
5354import Text.Pandoc.Shared
@@ -384,14 +385,18 @@ inlineToMuse (Link _ txt (src, _)) =
384385 isImageUrl = (`elem` imageExtensions) . takeExtension
385386inlineToMuse (Image attr alt (source,'f':'i':'g':':':title)) =
386387 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
388390 alt <- inlineListToMuse inlines
389391 let title' = if null title
390392 then if null inlines
391393 then ""
392394 else "[" <> alt <> "]"
393395 else "[" <> text title <> "]"
394− return $ "[[" <> text source <> "]" <> title' <> "]"
396+ let width = case dimension Width attr of
397+ Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
398+ _ -> ""
399+ return $ "[[" <> text (source ++ width) <> "]" <> title' <> "]"
395400inlineToMuse (Note contents) = do
396401 -- add to notes in state
397402 notes <- gets stNotes
test/Tests/Writers/Muse.hs+3
@@ -351,6 +351,9 @@ tests = [ testGroup "block elements"
351351 =?> "[[URL:1.png]]"
352352 ]
353353 , "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]]"
354357 , "note" =: note (plain (text "Foo"))
355358 =?> unlines [ "[1]"
356359 , ""