diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2018-05-27 23:57:19 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2018-05-27 23:58:02 +0300 |
commit | 91aceeeff336e2bcaf56b8c9610c53f79ba40cb6 (patch) | |
tree | db51cde12a829f8bc919a3a371c0eab459440fc4 | |
parent | 6907985e82b5ac2ae98bf787738fc9ad3a402026 (diff) | |
download | pandoc-91aceeeff336e2bcaf56b8c9610c53f79ba40cb6.tar.gz |
Muse reader: parse links starting with "URL:" explicitly
instead of trying to strip "URL:" prefix after parsing.
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index fe6b3698c..e49648506 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -46,7 +46,7 @@ import Control.Monad.Except (throwError) import Data.Bifunctor import Data.Char (isLetter) import Data.Default -import Data.List (stripPrefix, intercalate) +import Data.List (intercalate) import Data.List.Split (splitOn) import qualified Data.Map as M import qualified Data.Set as Set @@ -947,24 +947,31 @@ link = try $ do st <- getState guard $ not $ museInLink st setState $ st{ museInLink = True } - (url, content) <- linkText + res <- explicitLink <|> linkText updateState (\state -> state { museInLink = False }) - return $ case stripPrefix "URL:" url of - Nothing -> if isImageUrl url - then B.image url "" <$> fromMaybe (return mempty) content - else B.link url "" <$> fromMaybe (return $ B.str url) content - Just url' -> B.link url' "" <$> fromMaybe (return $ B.str url') 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 + return res linkContent :: PandocMonad m => MuseParser m (F Inlines) linkContent = char '[' >> trimInlinesF . mconcat <$> manyTill inline (string "]") -linkText :: PandocMonad m => MuseParser m (String, Maybe (F Inlines)) +-- | Parse a link starting with @URL:@ +explicitLink :: PandocMonad m => MuseParser m (F Inlines) +explicitLink = try $ do + string "[[URL:" + url <- manyTill anyChar $ char ']' + content <- option (pure $ B.str url) linkContent + char ']' + return $ B.link url "" <$> content + +linkText :: PandocMonad m => MuseParser m (F Inlines) linkText = do string "[[" url <- manyTill anyChar $ char ']' content <- optionMaybe linkContent char ']' - return (url, content) + return $ if isImageUrl url + then B.image url "" <$> fromMaybe (return mempty) content + else B.link url "" <$> fromMaybe (return $ B.str url) 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 |