git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: add support for images with specified width
commit1f78efff3b903158da557dbe83c2350954d40a2e authorAlexander Krotov <ilabdsf@gmail.com> dateThu 31 May 2018, 00:57 (8 years ago) parentf4b71d9
2 files changed+15−4
src/Text/Pandoc/Readers/Muse.hs+9−4 test/Tests/Readers/Muse.hs+6
src/Text/Pandoc/Readers/Muse.hs+9−4
@@ -35,7 +35,7 @@ TODO:
3535- Page breaks (five "*")
3636- Org tables
3737- table.el tables
38−- Images with attributes (floating and width)
38+- Floating images
3939- <cite> tag
4040-}
4141module Text.Pandoc.Readers.Muse (readMuse) where
@@ -50,7 +50,7 @@ import Data.List (intercalate)
5050import Data.List.Split (splitOn)
5151import qualified Data.Map as M
5252import qualified Data.Set as Set
53−import Data.Maybe (fromMaybe, isNothing)
53+import Data.Maybe (fromMaybe, isNothing, maybeToList)
5454import Data.Text (Text, unpack)
5555import Text.HTML.TagSoup
5656import Text.Pandoc.Builder (Blocks, Inlines)
@@ -965,13 +965,18 @@ explicitLink = try $ do
965965image :: PandocMonad m => MuseParser m (F Inlines)
966966image = try $ do
967967 string "[["
968− (url, ext) <- manyUntil (noneOf "]") $ (imageExtension <* char ']')
968+ (url, (ext, width)) <- manyUntil (noneOf "]") $ (imageExtensionAndOptions <* char ']')
969969 content <- optionMaybe linkContent
970970 char ']'
971− return $ B.image (url ++ ext) "" <$> fromMaybe (return mempty) content
971+ let widthAttr = maybeToList (("width",) . (++ "%") <$> width)
972+ return $ B.imageWith ("", [], widthAttr) (url ++ ext) mempty <$> fromMaybe (return mempty) content
972973 where -- Taken from muse-image-regexp defined in Emacs Muse file lisp/muse-regexps.el
973974 imageExtensions = [".eps", ".gif", ".jpg", ".jpeg", ".pbm", ".png", ".tiff", ".xbm", ".xpm"]
974975 imageExtension = choice (try . string <$> imageExtensions)
976+ imageExtensionAndOptions = do
977+ ext <- imageExtension
978+ width <- optionMaybe (many1 spaceChar *> many1 digit)
979+ return (ext, width)
975980
976981link :: PandocMonad m => MuseParser m (F Inlines)
977982link = try $ do
test/Tests/Readers/Muse.hs+6
@@ -203,6 +203,12 @@ tests =
203203 , "Image with space in filename" =:
204204 "[[image name.jpg]]" =?>
205205 para (image "image name.jpg" "" mempty)
206+ , "Image with width" =:
207+ "[[image.jpg 60]]" =?>
208+ para (imageWith ("", [], [("width", "60%")]) "image.jpg" mempty mempty)
209+ , "At least one space is required between image filename and width" =:
210+ "[[image.jpg60]]" =?>
211+ para (link "image.jpg60" mempty (str "image.jpg60"))
206212 , "Image link" =:
207213 "[[URL:image.jpg]]" =?>
208214 para (link "image.jpg" "" (str "image.jpg"))