git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: add support for left-align and right-align classes

Address issue #4542

commit58799234227200b480b21a8f6611bdf3b6e2528a authorAlexander Krotov <ilabdsf@gmail.com> dateMon 7 May 2018, 14:54 (8 years ago) parent621e864
2 files changed+14−2
src/Text/Pandoc/Writers/Muse.hs+8−2 test/Tests/Writers/Muse.hs+6
src/Text/Pandoc/Writers/Muse.hs+8−2
@@ -511,7 +511,7 @@ inlineToMuse (Link _ txt (src, _)) =
511511 isImageUrl = (`elem` imageExtensions) . takeExtension
512512inlineToMuse (Image attr alt (source,'f':'i':'g':':':title)) =
513513 inlineToMuse (Image attr alt (source,title))
514−inlineToMuse (Image attr inlines (source, title)) = do
514+inlineToMuse (Image attr@(_, classes, _) inlines (source, title)) = do
515515 opts <- asks envOptions
516516 alt <- local (\env -> env { envInsideLinkDescription = True }) $ inlineListToMuse inlines
517517 let title' = if null title
@@ -522,7 +522,13 @@ inlineToMuse (Image attr inlines (source, title)) = do
522522 let width = case dimension Width attr of
523523 Just (Percent x) | isEnabled Ext_amuse opts -> " " ++ show (round x :: Integer)
524524 _ -> ""
525− return $ "[[" <> text (urlEscapeBrackets source ++ width) <> "]" <> title' <> "]"
525+ let leftalign = if "align-left" `elem` classes
526+ then " l"
527+ else ""
528+ let rightalign = if "align-right" `elem` classes
529+ then " r"
530+ else ""
531+ return $ "[[" <> text (urlEscapeBrackets source ++ width ++ leftalign ++ rightalign) <> "]" <> title' <> "]"
526532inlineToMuse (Note contents) = do
527533 -- add to notes in state
528534 notes <- gets stNotes
test/Tests/Writers/Muse.hs+6
@@ -425,6 +425,12 @@ tests = [ testGroup "block elements"
425425 , "image with width" =:
426426 imageWith ("", [], [("width", "60%")]) "image.png" "Image" (str "") =?>
427427 "[[image.png 60][Image]]"
428+ , "left-aligned image with width" =:
429+ imageWith ("", ["align-left"], [("width", "60%")]) "image.png" "Image" (str "") =?>
430+ "[[image.png 60 l][Image]]"
431+ , "right-aligned image with width" =:
432+ imageWith ("", ["align-right"], [("width", "60%")]) "image.png" "Image" (str "") =?>
433+ "[[image.png 60 r][Image]]"
428434 , "escape brackets in image title" =: image "image.png" "Foo]bar" (str "") =?> "[[image.png][<verbatim>Foo]bar</verbatim>]]"
429435 , "note" =: note (plain (text "Foo"))
430436 =?> unlines [ "[1]"