From 5a304360d0c871e95cbc4c61a5d5127ebbe99651 Mon Sep 17 00:00:00 2001
From: Alexander Krotov <ilabdsf@gmail.com>
Date: Tue, 13 Feb 2018 14:13:00 +0300
Subject: [PATCH] Muse reader: parse next list item before parsing more item
 contents

---
 src/Text/Pandoc/Readers/Muse.hs | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index c8ebe1883..18d4104ff 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -305,26 +305,29 @@ parseBlocksTill end =
 listItemContentsUntil :: PandocMonad m
                       => Int
                       -> MuseParser m a
+                      -> MuseParser m a
                       -> MuseParser m (F Blocks, a)
-listItemContentsUntil col end =
+listItemContentsUntil col pre end =
   try blockStart <|>
   try listStart <|>
   try paraStart
   where
+    parsePre = do e <- pre
+                  return (mempty, e)
     parseEnd = do e <- end
                   return (mempty, e)
     paraStart = do
-      (first, e) <- paraUntil ((Right <$> continuation) <|> (Left <$> end))
+      (first, e) <- paraUntil ((Left <$> pre) <|> (Right <$> continuation) <|> (Left <$> end))
       case e of
         Left ee -> return (first, ee)
         Right (rest, ee) -> return (first B.<> rest, ee)
     blockStart = do first <- blockElements
-                    (rest, e) <- continuation <|> parseEnd
+                    (rest, e) <- parsePre <|> continuation <|> parseEnd
                     return (first B.<> rest, e)
     listStart = do
       st <- getState
       setState $ st{ museInPara = False }
-      (first, e) <- anyListUntil ((Right <$> continuation) <|> (Left <$> end))
+      (first, e) <- anyListUntil ((Left <$> pre) <|> (Right <$> continuation) <|> (Left <$> end))
       case e of
         Left ee -> return (first, ee)
         Right (rest, ee) -> return $ (first B.<> rest, ee)
@@ -333,7 +336,7 @@ listItemContentsUntil col end =
                             indentWith col
                             st <- getState
                             setState $ st{ museInPara = museInPara st && isNothing blank }
-                            listItemContentsUntil col end
+                            listItemContentsUntil col pre end
 
 parseBlock :: PandocMonad m => MuseParser m (F Blocks)
 parseBlock = do
@@ -554,7 +557,7 @@ bulletListItemsUntil indent end = try $ do
   void spaceChar <|> lookAhead eol
   st <- getState
   setState $ st{ museInPara = False }
-  (x, e) <- listItemContentsUntil (indent + 2) ((Right <$> try (optional blankline >> indentWith indent >> bulletListItemsUntil indent end)) <|> (Left <$> end))
+  (x, e) <- listItemContentsUntil (indent + 2) (Right <$> try (optional blankline >> indentWith indent >> bulletListItemsUntil indent end)) (Left <$> end)
   case e of
     Left ee -> return ([x], ee)
     Right (xs, ee) -> return (x:xs, ee)
@@ -610,7 +613,7 @@ orderedListItemsUntil indent style end =
       void spaceChar <|> lookAhead eol
       st <- getState
       setState $ st{ museInPara = False }
-      (x, e) <- listItemContentsUntil (sourceColumn pos) ((Right <$> try (optionMaybe blankline >> indentWith indent >> museOrderedListMarker style >> continuation)) <|> (Left <$> end))
+      (x, e) <- listItemContentsUntil (sourceColumn pos) (Right <$> try (optionMaybe blankline >> indentWith indent >> museOrderedListMarker style >> continuation)) (Left <$> end)
       case e of
         Left ee -> return ([x], ee)
         Right (xs, ee) -> return (x:xs, ee)