aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-05-28 01:24:09 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-05-28 01:24:09 +0300
commitbdf8c01f2c0e3d3cd549c19b118c332cd48eeeb0 (patch)
tree97d091804cb00fa23482f00629231fa7379886dc /src
parent91aceeeff336e2bcaf56b8c9610c53f79ba40cb6 (diff)
downloadpandoc-bdf8c01f2c0e3d3cd549c19b118c332cd48eeeb0.tar.gz
Muse reader: split link and image parsing into separate functions
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index e49648506..e8b7d24f7 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -778,7 +778,7 @@ inlineList = [ whitespace
, verbatimTag
, classTag
, nbsp
- , link
+ , linkOrImage
, code
, codeTag
, mathTag
@@ -942,17 +942,17 @@ symbol :: PandocMonad m => MuseParser m (F Inlines)
symbol = return . B.str <$> count 1 nonspaceChar
-- | Parse a link or image.
-link :: PandocMonad m => MuseParser m (F Inlines)
-link = try $ do
+linkOrImage :: PandocMonad m => MuseParser m (F Inlines)
+linkOrImage = try $ do
st <- getState
guard $ not $ museInLink st
setState $ st{ museInLink = True }
- res <- explicitLink <|> linkText
+ res <- explicitLink <|> image <|> link
updateState (\state -> state { museInLink = False })
return res
linkContent :: PandocMonad m => MuseParser m (F Inlines)
-linkContent = char '[' >> trimInlinesF . mconcat <$> manyTill inline (string "]")
+linkContent = char '[' >> trimInlinesF . mconcat <$> manyTill inline (char ']')
-- | Parse a link starting with @URL:@
explicitLink :: PandocMonad m => MuseParser m (F Inlines)
@@ -963,15 +963,22 @@ explicitLink = try $ do
char ']'
return $ B.link url "" <$> content
-linkText :: PandocMonad m => MuseParser m (F Inlines)
-linkText = do
+image :: PandocMonad m => MuseParser m (F Inlines)
+image = try $ do
string "[["
url <- manyTill anyChar $ char ']'
content <- optionMaybe linkContent
char ']'
- return $ if isImageUrl url
- then B.image url "" <$> fromMaybe (return mempty) content
- else B.link url "" <$> fromMaybe (return $ B.str url) content
+ guard $ isImageUrl url
+ return $ B.image url "" <$> 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
+
+link :: PandocMonad m => MuseParser m (F Inlines)
+link = try $ do
+ string "[["
+ url <- manyTill anyChar $ char ']'
+ content <- optionMaybe linkContent
+ char ']'
+ return $ B.link url "" <$> fromMaybe (return $ B.str url) content