@@ -83,7 +83,6 @@ data MuseState = MuseState { museMeta :: F Meta -- ^ Document metadata
83 , museLastStrPos :: Maybe SourcePos -- ^ Position after last str parsed
83 , museLastStrPos :: Maybe SourcePos -- ^ Position after last str parsed
84 , museLogMessages :: [LogMessage]
84 , museLogMessages :: [LogMessage]
85 , museNotes :: M.Map String (SourcePos, F Blocks)
85 , museNotes :: M.Map String (SourcePos, F Blocks)
86− , museInPara :: Bool -- ^ True when looking for a paragraph terminator
89instance Default MuseState where
88instance Default MuseState where
@@ -94,15 +93,17 @@ instance Default MuseState where
94 , museLastStrPos = Nothing
93 , museLastStrPos = Nothing
95 , museLogMessages = []
94 , museLogMessages = []
96 , museNotes = M.empty
95 , museNotes = M.empty
100data MuseEnv =
98data MuseEnv =
101 MuseEnv { museInLink :: Bool -- ^ True when parsing a link description to avoid nested links
99 MuseEnv { museInLink :: Bool -- ^ True when parsing a link description to avoid nested links
100+ , museInPara :: Bool -- ^ True when parsing paragraph is not allowed
104instance Default MuseEnv where
103instance Default MuseEnv where
105− def = MuseEnv { museInLink = False }
104+ def = MuseEnv { museInLink = False
105+ , museInPara = False
107type MuseParser m = ParserT Text MuseState (ReaderT MuseEnv m)
108type MuseParser m = ParserT Text MuseState (ReaderT MuseEnv m)
@@ -214,7 +215,7 @@ parseHtmlContent :: PandocMonad m
214parseHtmlContent tag = try $ getIndent >>= \indent -> (,)
215parseHtmlContent tag = try $ getIndent >>= \indent -> (,)
215 <$> fmap htmlAttrToPandoc (openTag tag)
216 <$> fmap htmlAttrToPandoc (openTag tag)
216 <* manyTill spaceChar eol
217 <* manyTill spaceChar eol
217− <*> parseBlocksTill (try $ count indent spaceChar *> closeTag tag)
218+ <*> allowPara (parseBlocksTill (try $ count indent spaceChar *> closeTag tag))
218 <* manyTill spaceChar eol -- closing tag must be followed by optional whitespace and newline
219 <* manyTill spaceChar eol -- closing tag must be followed by optional whitespace and newline
220-- ** Directive parsers
221-- ** Directive parsers
@@ -248,6 +249,9 @@ directive = do
249-- ** Block parsers
250-- ** Block parsers
252+allowPara :: MonadReader MuseEnv m => m a -> m a
253+allowPara p = local (\s -> s { museInPara = False }) p
251-- | Parse section contents until EOF or next header
255-- | Parse section contents until EOF or next header
252parseBlocks :: PandocMonad m
256parseBlocks :: PandocMonad m
253 => MuseParser m (F Blocks)
257 => MuseParser m (F Blocks)
@@ -261,10 +265,9 @@ parseBlocks =
261 nextSection = mempty <$ lookAhead headingStart
265 nextSection = mempty <$ lookAhead headingStart
262 parseEnd = mempty <$ eof
266 parseEnd = mempty <$ eof
263 blockStart = (B.<>) <$> (blockElements <|> emacsNoteBlock)
267 blockStart = (B.<>) <$> (blockElements <|> emacsNoteBlock)
264− <*> parseBlocks
268+ <*> allowPara parseBlocks
265− listStart = do
269+ listStart =
266− updateState (\st -> st { museInPara = False })
267− uncurry (B.<>) <$> (anyListUntil parseBlocks <|> amuseNoteBlockUntil parseBlocks)
270+ uncurry (B.<>) <$> allowPara (anyListUntil parseBlocks <|> amuseNoteBlockUntil parseBlocks)
268 paraStart = do
271 paraStart = do
269 indent <- length <$> many spaceChar
272 indent <- length <$> many spaceChar
270 uncurry (B.<>) . first (p indent) <$> paraUntil parseBlocks
273 uncurry (B.<>) . first (p indent) <$> paraUntil parseBlocks
@@ -287,10 +290,8 @@ parseBlocksTill end =
287 paraStart)
290 paraStart)
289 parseEnd = mempty <$ end
292 parseEnd = mempty <$ end
290− blockStart = (B.<>) <$> blockElements <*> continuation
293+ blockStart = (B.<>) <$> blockElements <*> allowPara continuation
292− updateState (\st -> st { museInPara = False })
293− uncurry (B.<>) <$> anyListUntil (parseEnd <|> continuation)
294+ listStart = uncurry (B.<>) <$> allowPara (anyListUntil (parseEnd <|> continuation))
294 paraStart = uncurry (B.<>) <$> paraUntil (parseEnd <|> continuation)
295 paraStart = uncurry (B.<>) <$> paraUntil (parseEnd <|> continuation)
295 continuation = parseBlocksTill end
296 continuation = parseBlocksTill end
@@ -310,16 +311,14 @@ listItemContentsUntil col pre end =
310 (f, (r, e)) <- paraUntil (parsePre <|> continuation <|> parseEnd)
311 (f, (r, e)) <- paraUntil (parsePre <|> continuation <|> parseEnd)
311 return (f B.<> r, e)
312 return (f B.<> r, e)
312 blockStart = first <$> ((B.<>) <$> blockElements)
313 blockStart = first <$> ((B.<>) <$> blockElements)
313− <*> (parsePre <|> continuation <|> parseEnd)
314+ <*> allowPara (parsePre <|> continuation <|> parseEnd)
314 listStart = do
315 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)
317 return (f B.<> r, e)
317 return (f B.<> r, e)
318 continuation = try $ do blank <- optionMaybe blankline
318 continuation = try $ do blank <- optionMaybe blankline
319 skipMany blankline
319 skipMany blankline
320 indentWith col
320 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
324parseBlock :: PandocMonad m => MuseParser m (F Blocks)
323parseBlock :: PandocMonad m => MuseParser m (F Blocks)
325parseBlock = do
324parseBlock = do
@@ -329,8 +328,7 @@ parseBlock = do
329 where para = fst <$> paraUntil (try (eof <|> void (lookAhead blockElements)))
328 where para = fst <$> paraUntil (try (eof <|> void (lookAhead blockElements)))
331blockElements :: PandocMonad m => MuseParser m (F Blocks)
330blockElements :: PandocMonad m => MuseParser m (F Blocks)
332−blockElements = do
331+blockElements =
333− updateState (\st -> st { museInPara = False })
334 choice [ mempty <$ blankline
332 choice [ mempty <$ blankline
335 , comment
333 , comment
336 , separator
334 , separator
@@ -479,19 +477,16 @@ commentTag = try $ mempty
479paraContentsUntil :: PandocMonad m
477paraContentsUntil :: PandocMonad m
480 => MuseParser m a -- ^ Terminator parser
478 => MuseParser m a -- ^ Terminator parser
481 -> MuseParser m (F Inlines, a)
479 -> MuseParser m (F Inlines, a)
482−paraContentsUntil end = do
480+paraContentsUntil end = first (trimInlinesF . mconcat)
483− updateState (\st -> st { museInPara = True })
484− (l, e) <- someUntil inline $ try (manyTill spaceChar eol *> end)
481+ <$> someUntil inline (try (manyTill spaceChar eol *> local (\s -> s { museInPara = True}) end))
485− updateState (\st -> st { museInPara = False })
486− return (trimInlinesF $ mconcat l, e)
488-- | Parse a paragraph.
483-- | Parse a paragraph.
489paraUntil :: PandocMonad m
484paraUntil :: PandocMonad m
490 => MuseParser m a -- ^ Terminator parser
485 => MuseParser m a -- ^ Terminator parser
491 -> MuseParser m (F Blocks, a)
486 -> MuseParser m (F Blocks, a)
492paraUntil end = do
487paraUntil end = do
493− state <- getState
488+ inPara <- asks museInPara
494− guard $ not $ museInPara state
489+ guard $ not inPara
495 first (fmap B.para) <$> paraContentsUntil end
490 first (fmap B.para) <$> paraContentsUntil end
497noteMarker :: PandocMonad m => MuseParser m String
492noteMarker :: PandocMonad m => MuseParser m String
@@ -509,8 +504,7 @@ amuseNoteBlockUntil end = try $ do
509 guardEnabled Ext_amuse
504 guardEnabled Ext_amuse
510 ref <- noteMarker <* spaceChar
505 ref <- noteMarker <* spaceChar
511 pos <- getPosition
506 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
514 oldnotes <- museNotes <$> getState
508 oldnotes <- museNotes <$> getState
515 when (M.member ref oldnotes)
509 when (M.member ref oldnotes)
516 (logMessage $ DuplicateNoteReference ref pos)
510 (logMessage $ DuplicateNoteReference ref pos)
@@ -555,8 +549,7 @@ bulletListItemsUntil :: PandocMonad m
555bulletListItemsUntil indent end = try $ do
549bulletListItemsUntil indent end = try $ do
557 void spaceChar <|> lookAhead eol
551 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)
560 return (x:xs, e)
553 return (x:xs, e)
562-- | Parse a bullet list.
555-- | Parse a bullet list.
@@ -592,8 +585,7 @@ orderedListItemsUntil indent style end =
592 continuation = try $ do
585 continuation = try $ do
593 pos <- getPosition
586 pos <- getPosition
594 void spaceChar <|> lookAhead eol
587 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)
597 return (x:xs, e)
589 return (x:xs, e)
599-- | Parse an ordered list.
591-- | Parse an ordered list.
@@ -614,8 +606,7 @@ descriptionsUntil :: PandocMonad m
614 -> MuseParser m ([F Blocks], a)
606 -> MuseParser m ([F Blocks], a)
615descriptionsUntil indent end = do
607descriptionsUntil indent end = do
616 void spaceChar <|> lookAhead eol
608 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)
619 return (x:xs, e)
610 return (x:xs, e)
621definitionListItemsUntil :: PandocMonad m
612definitionListItemsUntil :: PandocMonad m