@@ -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