@@ -83,7 +83,6 @@ data MuseState = MuseState { museMeta :: F Meta -- ^ Document metadata
8383 , museLastStrPos :: Maybe SourcePos -- ^ Position after last str parsed
8484 , museLogMessages :: [LogMessage]
8585 , museNotes :: M.Map String (SourcePos, F Blocks)
86− , museInPara :: Bool -- ^ True when looking for a paragraph terminator
8786 }
8887
8988instance Default MuseState where
@@ -94,15 +93,17 @@ instance Default MuseState where
9493 , museLastStrPos = Nothing
9594 , museLogMessages = []
9695 , museNotes = M.empty
97− , museInPara = False
9896 }
9997
10098data MuseEnv =
10199 MuseEnv { museInLink :: Bool -- ^ True when parsing a link description to avoid nested links
100+ , museInPara :: Bool -- ^ True when parsing paragraph is not allowed
102101 }
103102
104103instance Default MuseEnv where
105− def = MuseEnv { museInLink = False }
104+ def = MuseEnv { museInLink = False
105+ , museInPara = False
106+ }
106107
107108type MuseParser m = ParserT Text MuseState (ReaderT MuseEnv m)
108109
@@ -214,7 +215,7 @@ parseHtmlContent :: PandocMonad m
214215parseHtmlContent tag = try $ getIndent >>= \indent -> (,)
215216 <$> fmap htmlAttrToPandoc (openTag tag)
216217 <* manyTill spaceChar eol
217− <*> parseBlocksTill (try $ count indent spaceChar *> closeTag tag)
218+ <*> allowPara (parseBlocksTill (try $ count indent spaceChar *> closeTag tag))
218219 <* manyTill spaceChar eol -- closing tag must be followed by optional whitespace and newline
219220
220221-- ** Directive parsers
@@ -248,6 +249,9 @@ directive = do
248249
249250-- ** Block parsers
250251
252+allowPara :: MonadReader MuseEnv m => m a -> m a
253+allowPara p = local (\s -> s { museInPara = False }) p
254+
251255-- | Parse section contents until EOF or next header
252256parseBlocks :: PandocMonad m
253257 => MuseParser m (F Blocks)
@@ -261,10 +265,9 @@ parseBlocks =
261265 nextSection = mempty <$ lookAhead headingStart
262266 parseEnd = mempty <$ eof
263267 blockStart = (B.<>) <$> (blockElements <|> emacsNoteBlock)
264− <*> parseBlocks
265− listStart = do
266− updateState (\st -> st { museInPara = False })
267− uncurry (B.<>) <$> (anyListUntil parseBlocks <|> amuseNoteBlockUntil parseBlocks)
268+ <*> allowPara parseBlocks
269+ listStart =
270+ uncurry (B.<>) <$> allowPara (anyListUntil parseBlocks <|> amuseNoteBlockUntil parseBlocks)
268271 paraStart = do
269272 indent <- length <$> many spaceChar
270273 uncurry (B.<>) . first (p indent) <$> paraUntil parseBlocks
@@ -287,10 +290,8 @@ parseBlocksTill end =
287290 paraStart)
288291 where
289292 parseEnd = mempty <$ end
290− blockStart = (B.<>) <$> blockElements <*> continuation
291− listStart = do
292− updateState (\st -> st { museInPara = False })
293− uncurry (B.<>) <$> anyListUntil (parseEnd <|> continuation)
293+ blockStart = (B.<>) <$> blockElements <*> allowPara continuation
294+ listStart = uncurry (B.<>) <$> allowPara (anyListUntil (parseEnd <|> continuation))
294295 paraStart = uncurry (B.<>) <$> paraUntil (parseEnd <|> continuation)
295296 continuation = parseBlocksTill end
296297
@@ -310,16 +311,14 @@ listItemContentsUntil col pre end =
310311 (f, (r, e)) <- paraUntil (parsePre <|> continuation <|> parseEnd)
311312 return (f B.<> r, e)
312313 blockStart = first <$> ((B.<>) <$> blockElements)
313− <*> (parsePre <|> continuation <|> parseEnd)
314+ <*> allowPara (parsePre <|> continuation <|> parseEnd)
314315 listStart = do
315− updateState (\st -> st { museInPara = False })
316− (f, (r, e)) <- anyListUntil (parsePre <|> continuation <|> parseEnd)
316+ (f, (r, e)) <- allowPara $ anyListUntil (parsePre <|> continuation <|> parseEnd)
317317 return (f B.<> r, e)
318318 continuation = try $ do blank <- optionMaybe blankline
319319 skipMany blankline
320320 indentWith col
321− updateState (\st -> st { museInPara = museInPara st && isNothing blank })
322− listItemContentsUntil col pre end
321+ local (\s -> s { museInPara = museInPara s && isNothing blank }) $ listItemContentsUntil col pre end
323322
324323parseBlock :: PandocMonad m => MuseParser m (F Blocks)
325324parseBlock = do
@@ -329,8 +328,7 @@ parseBlock = do
329328 where para = fst <$> paraUntil (try (eof <|> void (lookAhead blockElements)))
330329
331330blockElements :: PandocMonad m => MuseParser m (F Blocks)
332−blockElements = do
333− updateState (\st -> st { museInPara = False })
331+blockElements =
334332 choice [ mempty <$ blankline
335333 , comment
336334 , separator
@@ -479,19 +477,16 @@ commentTag = try $ mempty
479477paraContentsUntil :: PandocMonad m
480478 => MuseParser m a -- ^ Terminator parser
481479 -> MuseParser m (F Inlines, a)
482−paraContentsUntil end = do
483− updateState (\st -> st { museInPara = True })
484− (l, e) <- someUntil inline $ try (manyTill spaceChar eol *> end)
485− updateState (\st -> st { museInPara = False })
486− return (trimInlinesF $ mconcat l, e)
480+paraContentsUntil end = first (trimInlinesF . mconcat)
481+ <$> someUntil inline (try (manyTill spaceChar eol *> local (\s -> s { museInPara = True}) end))
487482
488483-- | Parse a paragraph.
489484paraUntil :: PandocMonad m
490485 => MuseParser m a -- ^ Terminator parser
491486 -> MuseParser m (F Blocks, a)
492487paraUntil end = do
493− state <- getState
494− guard $ not $ museInPara state
488+ inPara <- asks museInPara
489+ guard $ not inPara
495490 first (fmap B.para) <$> paraContentsUntil end
496491
497492noteMarker :: PandocMonad m => MuseParser m String
@@ -509,8 +504,7 @@ amuseNoteBlockUntil end = try $ do
509504 guardEnabled Ext_amuse
510505 ref <- noteMarker <* spaceChar
511506 pos <- getPosition
512− updateState (\st -> st { museInPara = False })
513− (content, e) <- listItemContentsUntil (sourceColumn pos - 1) (fail "x") end
507+ (content, e) <- allowPara $ listItemContentsUntil (sourceColumn pos - 1) (fail "x") end
514508 oldnotes <- museNotes <$> getState
515509 when (M.member ref oldnotes)
516510 (logMessage $ DuplicateNoteReference ref pos)
@@ -555,8 +549,7 @@ bulletListItemsUntil :: PandocMonad m
555549bulletListItemsUntil indent end = try $ do
556550 char '-'
557551 void spaceChar <|> lookAhead eol
558− updateState (\st -> st { museInPara = False })
559− (x, (xs, e)) <- listItemContentsUntil (indent + 2) (try (optional blankline *> indentWith indent *> bulletListItemsUntil indent end)) (([],) <$> end)
552+ (x, (xs, e)) <- allowPara $ listItemContentsUntil (indent + 2) (try (optional blankline *> indentWith indent *> bulletListItemsUntil indent end)) (([],) <$> end)
560553 return (x:xs, e)
561554
562555-- | Parse a bullet list.
@@ -592,8 +585,7 @@ orderedListItemsUntil indent style end =
592585 continuation = try $ do
593586 pos <- getPosition
594587 void spaceChar <|> lookAhead eol
595− updateState (\st -> st { museInPara = False })
596− (x, (xs, e)) <- listItemContentsUntil (sourceColumn pos) (try (optional blankline *> indentWith indent *> museOrderedListMarker style *> continuation)) (([],) <$> end)
588+ (x, (xs, e)) <- allowPara $ listItemContentsUntil (sourceColumn pos) (try (optional blankline *> indentWith indent *> museOrderedListMarker style *> continuation)) (([],) <$> end)
597589 return (x:xs, e)
598590
599591-- | Parse an ordered list.
@@ -614,8 +606,7 @@ descriptionsUntil :: PandocMonad m
614606 -> MuseParser m ([F Blocks], a)
615607descriptionsUntil indent end = do
616608 void spaceChar <|> lookAhead eol
617− updateState (\st -> st { museInPara = False })
618− (x, (xs, e)) <- listItemContentsUntil indent (try (optional blankline *> indentWith indent *> manyTill spaceChar (string "::") *> descriptionsUntil indent end)) (([],) <$> end)
609+ (x, (xs, e)) <- allowPara $ listItemContentsUntil indent (try (optional blankline *> indentWith indent *> manyTill spaceChar (string "::") *> descriptionsUntil indent end)) (([],) <$> end)
619610 return (x:xs, e)
620611
621612definitionListItemsUntil :: PandocMonad m