git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1645 from neongreen/issue1636

Fix 'Ext_lists_without_preceding_blankline' bug.

commit43c1978faebe17add5541b0a8e025b2e8d5c511a authorJohn MacFarlane <jgm@berkeley.edu> dateWed 12 Nov 2014, 09:05 (12 years ago) parent1cd6534bc115ff
2 files changed+21−2
src/Text/Pandoc/Readers/Markdown.hs+9−2 tests/Tests/Readers/Markdown.hs+12
src/Text/Pandoc/Readers/Markdown.hs+9−2
@@ -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
tests/Tests/Readers/Markdown.hs+12
@@ -20,6 +20,9 @@ markdownCDL :: String -> Pandoc
2020markdownCDL = readMarkdown def { readerExtensions = Set.insert
2121 Ext_compact_definition_lists $ readerExtensions def }
2222
23+markdownGH :: String -> Pandoc
24+markdownGH = readMarkdown def { readerExtensions = githubMarkdownExtensions }
25+
2326infix 4 =:
2427(=:) :: ToString c
2528 => String -> (String, c) -> Test
@@ -271,5 +274,14 @@ tests = [ testGroup "inline code"
271274 plain (text "if this button exists") <>
272275 rawBlock "html" "</button>" <>
273276 divWith nullAttr (para $ text "with this div too.")]
277+ , test markdownGH "issue #1636" $
278+ unlines [ "* a"
279+ , "* b"
280+ , "* c"
281+ , " * d" ]
282+ =?>
283+ bulletList [ plain "a"
284+ , plain "b"
285+ , plain "c" <> bulletList [plain "d"] ]
274286 ]
275287 ]