git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Headers: don't parse content over newline boundary.

Closes #5714.

commit167fc4bc8732b72cccda0c37139fee3ab94b05cb authorJohn MacFarlane <jgm@berkeley.edu> dateTue 27 Aug 2019, 10:15 (7 years ago) parent7c03c26
2 files changed+28−4
src/Text/Pandoc/Readers/Markdown.hs+15−4 test/command/5714.md+13
src/Text/Pandoc/Readers/Markdown.hs+15−4
@@ -532,8 +532,13 @@ atxHeader = try $ do
532532 (char '.' <|> char ')') -- this would be a list
533533 guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
534534 skipSpaces
535− (text, raw) <- withRaw $
536− trimInlinesF . mconcat <$> many (notFollowedBy atxClosing >> inline)
535+ (text, raw) <- withRaw $ do
536+ oldAllowLineBreaks <- stateAllowLineBreaks <$> getState
537+ updateState $ \st -> st{ stateAllowLineBreaks = False }
538+ res <- trimInlinesF . mconcat <$>
539+ many (notFollowedBy atxClosing >> inline)
540+ updateState $ \st -> st{ stateAllowLineBreaks = oldAllowLineBreaks }
541+ return res
537542 attr <- atxClosing
538543 attr' <- registerHeader attr (runF text defaultParserState)
539544 guardDisabled Ext_implicit_header_references
@@ -576,8 +581,13 @@ setextHeader = try $ do
576581 -- unless necessary -- it gives a significant performance boost.
577582 lookAhead $ anyLine >> many1 (oneOf setextHChars) >> blankline
578583 skipSpaces
579− (text, raw) <- withRaw $
580− trimInlinesF . mconcat <$> many1 (notFollowedBy setextHeaderEnd >> inline)
584+ (text, raw) <- withRaw $ do
585+ oldAllowLineBreaks <- stateAllowLineBreaks <$> getState
586+ updateState $ \st -> st{ stateAllowLineBreaks = False }
587+ res <- trimInlinesF . mconcat <$>
588+ many (notFollowedBy setextHeaderEnd >> inline)
589+ updateState $ \st -> st{ stateAllowLineBreaks = oldAllowLineBreaks }
590+ return res
581591 attr <- setextHeaderEnd
582592 underlineChar <- oneOf setextHChars
583593 many (char underlineChar)
@@ -1730,6 +1740,7 @@ endline :: PandocMonad m => MarkdownParser m (F Inlines)
17301740endline = try $ do
17311741 newline
17321742 notFollowedBy blankline
1743+ getState >>= guard . stateAllowLineBreaks
17331744 -- parse potential list-starts differently if in a list:
17341745 notFollowedBy (inList >> listStart)
17351746 guardDisabled Ext_lists_without_preceding_blankline <|> notFollowedBy listStart
test/command/5714.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -t native
3+# hi _a
4+b_
5+
6+# hi _c
7+c
8+^D
9+[Header 1 ("hi-_a",[],[]) [Str "hi",Space,Str "_a"]
10+,Para [Str "b_"]
11+,Header 1 ("hi-_c",[],[]) [Str "hi",Space,Str "_c"]
12+,Para [Str "c"]]
13+```