aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-05-30 02:25:30 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-05-30 02:29:43 +0300
commit1100bfc0e67954760c0c1767018404bf0129dd01 (patch)
tree9d7211b8206690daca2c16da568db843106ca6f8
parentbdf8c01f2c0e3d3cd549c19b118c332cd48eeeb0 (diff)
downloadpandoc-1100bfc0e67954760c0c1767018404bf0129dd01.tar.gz
Muse reader: parse image URLs without "guard" and "takeExtension"
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs8
-rw-r--r--test/Tests/Readers/Muse.hs3
2 files changed, 6 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index e8b7d24f7..9eda0d4f3 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -52,7 +52,6 @@ import qualified Data.Map as M
import qualified Data.Set as Set
import Data.Maybe (fromMaybe, isNothing)
import Data.Text (Text, unpack)
-import System.FilePath (takeExtension)
import Text.HTML.TagSoup
import Text.Pandoc.Builder (Blocks, Inlines)
import qualified Text.Pandoc.Builder as B
@@ -966,14 +965,13 @@ explicitLink = try $ do
image :: PandocMonad m => MuseParser m (F Inlines)
image = try $ do
string "[["
- url <- manyTill anyChar $ char ']'
+ (url, ext) <- manyUntil (noneOf "]") $ (imageExtension <* char ']')
content <- optionMaybe linkContent
char ']'
- guard $ isImageUrl url
- return $ B.image url "" <$> fromMaybe (return mempty) content
+ return $ B.image (url ++ ext) "" <$> 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"]
- isImageUrl = (`elem` imageExtensions) . takeExtension
+ imageExtension = choice (try . string <$> imageExtensions)
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 ddfedbff4..6b4e0fdbd 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -194,6 +194,9 @@ tests =
, "Image" =:
"[[image.jpg]]" =?>
para (image "image.jpg" "" mempty)
+ , "Closing bracket is not allowed in image filename" =:
+ "[[foo]bar.jpg]]" =?>
+ para (text "[[foo]bar.jpg]]")
, "Image with description" =:
"[[image.jpg][Image]]" =?>
para (image "image.jpg" "" (text "Image"))