diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2018-10-10 11:35:00 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2018-10-10 11:35:00 +0300 |
commit | 0a7650f87b3ef9ec80e23377ced31d04c2474806 (patch) | |
tree | e6e77bc5db3fa1bdec82348471c25321090f5128 | |
parent | 6b8fd99dbdfba52a44d10b558fe88d5a2e1c2916 (diff) | |
download | pandoc-0a7650f87b3ef9ec80e23377ced31d04c2474806.tar.gz |
Muse reader internals: merge link and explicit link parsers into one function
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 39c5a296e..3522688ad 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -909,17 +909,17 @@ linkOrImage :: PandocMonad m => MuseParser m (F Inlines) linkOrImage = try $ do inLink <- asks museInLink guard $ not inLink - local (\s -> s { museInLink = True }) (explicitLink <|> image <|> link) + local (\s -> s { museInLink = True }) (link "URL:" <|> image <|> link "") linkContent :: PandocMonad m => MuseParser m (F Inlines) linkContent = trimInlinesF . mconcat <$ char '[' <*> manyTill inline (char ']') --- | Parse a link starting with @URL:@ -explicitLink :: PandocMonad m => MuseParser m (F Inlines) -explicitLink = try $ do - string "[[URL:" +-- | Parse a link starting with (possibly null) prefix +link :: PandocMonad m => String -> MuseParser m (F Inlines) +link prefix = try $ do + string $ "[[" ++ prefix url <- manyTill anyChar $ char ']' content <- option (pure $ B.str url) linkContent char ']' @@ -952,11 +952,3 @@ image = try $ do <*> optionMaybe (many1 digit) <* many spaceChar <*> optionMaybe (oneOf "rlf") - -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 |