From 36c763a64720ccba61d3bc4f10c286cb445d52fa Mon Sep 17 00:00:00 2001
From: Alexander Krotov <ilabdsf@gmail.com>
Date: Wed, 10 Oct 2018 03:11:34 +0300
Subject: [PATCH] Muse reader: rewrite code parser in applicative style

---
 src/Text/Pandoc/Readers/Muse.hs | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index 7aef9bd6d..39c5a296e 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -873,14 +873,11 @@ nbsp = try $ pure (B.str "\160") <$ string "~~"
 
 -- | Parse code markup, indicated by @\'=\'@ characters.
 code :: PandocMonad m => MuseParser m (F Inlines)
-code = try $ do
-  atStart $ char '='
-  contents <- many1Till (noneOf "\n\r" <|> (newline <* notFollowedBy newline)) $ char '='
-  guard $ not $ null contents
-  guard $ head contents `notElem` " \t\n"
-  guard $ last contents `notElem` " \t\n"
-  notFollowedBy $ satisfy isAlphaNum
-  return $ return $ B.code contents
+code = try $ fmap pure $ B.code . uncurry (++)
+  <$  atStart (char '=')
+  <*  notFollowedBy (spaceChar <|> newline)
+  <*> manyUntil (noneOf "\n\r" <|> (newline <* notFollowedBy newline)) (try $ fmap pure $ noneOf " \t\n\r=" <* char '=')
+  <*  notFollowedBy (satisfy isAlphaNum)
 
 -- | Parse @\<code>@ tag.
 codeTag :: PandocMonad m => MuseParser m (F Inlines)