aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs24
-rw-r--r--test/Tests/Readers/Muse.hs6
2 files changed, 24 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index 72909dc4d..6ff84bff1 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -35,7 +35,6 @@ TODO:
- Page breaks (five "*")
- Org tables
- table.el tables
-- Floating images
- <cite> tag
-}
module Text.Pandoc.Readers.Muse (readMuse) where
@@ -965,18 +964,31 @@ explicitLink = try $ do
image :: PandocMonad m => MuseParser m (F Inlines)
image = try $ do
string "[["
- (url, (ext, width)) <- manyUntil (noneOf "]") $ (imageExtensionAndOptions <* char ']')
+ (url, (ext, width, align)) <- manyUntil (noneOf "]") $ (imageExtensionAndOptions <* char ']')
content <- optionMaybe linkContent
char ']'
- let widthAttr = maybeToList (("width",) . (++ "%") <$> width)
- return $ B.imageWith ("", [], widthAttr) (url ++ ext) mempty <$> fromMaybe (return mempty) content
+ let widthAttr = case align of
+ Just 'f' -> [("width", (fromMaybe "100" width) ++ "%"), ("height", "75%")]
+ _ -> maybeToList (("width",) . (++ "%") <$> width)
+ let alignClass = case align of
+ Just 'r' -> ["align-right"]
+ Just 'l' -> ["align-left"]
+ Just 'f' -> []
+ Nothing -> []
+ return $ B.imageWith ("", alignClass, widthAttr) (url ++ ext) mempty <$> fromMaybe (return mempty) content
where -- Taken from muse-image-regexp defined in Emacs Muse file lisp/muse-regexps.el
imageExtensions = [".eps", ".gif", ".jpg", ".jpeg", ".pbm", ".png", ".tiff", ".xbm", ".xpm"]
imageExtension = choice (try . string <$> imageExtensions)
imageExtensionAndOptions = do
ext <- imageExtension
- width <- optionMaybe (many1 spaceChar *> many1 digit)
- return (ext, width)
+ (width, align) <- option (Nothing, Nothing) imageAttrs
+ return (ext, width, align)
+ imageAttrs = do
+ many1 spaceChar
+ width <- optionMaybe (many1 digit)
+ many spaceChar
+ align <- optionMaybe (oneOf "rlf")
+ return (width, align)
link :: PandocMonad m => MuseParser m (F Inlines)
link = try $ do
diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs
index 1146aa6d2..fe25e9c5d 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -209,6 +209,12 @@ tests =
, "At least one space is required between image filename and width" =:
"[[image.jpg60]]" =?>
para (link "image.jpg60" mempty (str "image.jpg60"))
+ , "Left-aligned image with width" =:
+ "[[image.png 60 l][Image]]" =?>
+ para (imageWith ("", ["align-left"], [("width", "60%")]) "image.png" "" (str "Image"))
+ , "Right-aligned image with width" =:
+ "[[image.png 60 r][Image]]" =?>
+ para (imageWith ("", ["align-right"], [("width", "60%")]) "image.png" "" (str "Image"))
, "Image link" =:
"[[URL:image.jpg]]" =?>
para (link "image.jpg" "" (str "image.jpg"))