@@ -117,6 +117,12 @@ isBlank _ = False
117117-- auxiliary functions
118118--
119119
120+-- | Succeeds when we're in list context.
121+inList :: MarkdownParser ()
122+inList = do
123+ ctx <- stateParserContext <$> getState
124+ guard (ctx == ListItemState)
125+
120126isNull :: F Inlines -> Bool
121127isNull ils = B.isNull $ runF ils def
122128
@@ -926,6 +932,8 @@ para = try $ do
926932 <|> (guardEnabled Ext_backtick_code_blocks >> () <$ lookAhead codeBlockFenced)
927933 <|> (guardDisabled Ext_blank_before_header >> () <$ lookAhead header)
928934 <|> (guardEnabled Ext_lists_without_preceding_blankline >>
935+ -- Avoid creating a paragraph in a nested list.
936+ notFollowedBy' inList >>
929937 () <$ lookAhead listStart)
930938 <|> do guardEnabled Ext_native_divs
931939 inHtmlBlock <- stateInHtmlBlock <$> getState
@@ -1610,8 +1618,7 @@ endline = try $ do
16101618 newline
16111619 notFollowedBy blankline
16121620 -- parse potential list-starts differently if in a list:
1613− st <- getState
1614− when (stateParserContext st == ListItemState) $ notFollowedBy listStart
1621+ notFollowedBy (inList >> listStart)
16151622 guardDisabled Ext_lists_without_preceding_blankline <|> notFollowedBy listStart
16161623 guardEnabled Ext_blank_before_blockquote <|> notFollowedBy emailBlockQuoteStart
16171624 guardEnabled Ext_blank_before_header <|> notFollowedBy (char '#') -- atx header