Markdown reader: Headers: don't parse content over newline boundary.

Closes #5714.
This commit is contained in:
John MacFarlane 2019-08-27 10:15:00 -07:00
parent 7c03c26d58
commit 167fc4bc87
2 changed files with 28 additions and 4 deletions

View file

@ -532,8 +532,13 @@ atxHeader = try $ do
(char '.' <|> char ')') -- this would be a list
guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
skipSpaces
(text, raw) <- withRaw $
trimInlinesF . mconcat <$> many (notFollowedBy atxClosing >> inline)
(text, raw) <- withRaw $ do
oldAllowLineBreaks <- stateAllowLineBreaks <$> getState
updateState $ \st -> st{ stateAllowLineBreaks = False }
res <- trimInlinesF . mconcat <$>
many (notFollowedBy atxClosing >> inline)
updateState $ \st -> st{ stateAllowLineBreaks = oldAllowLineBreaks }
return res
attr <- atxClosing
attr' <- registerHeader attr (runF text defaultParserState)
guardDisabled Ext_implicit_header_references
@ -576,8 +581,13 @@ setextHeader = try $ do
-- unless necessary -- it gives a significant performance boost.
lookAhead $ anyLine >> many1 (oneOf setextHChars) >> blankline
skipSpaces
(text, raw) <- withRaw $
trimInlinesF . mconcat <$> many1 (notFollowedBy setextHeaderEnd >> inline)
(text, raw) <- withRaw $ do
oldAllowLineBreaks <- stateAllowLineBreaks <$> getState
updateState $ \st -> st{ stateAllowLineBreaks = False }
res <- trimInlinesF . mconcat <$>
many (notFollowedBy setextHeaderEnd >> inline)
updateState $ \st -> st{ stateAllowLineBreaks = oldAllowLineBreaks }
return res
attr <- setextHeaderEnd
underlineChar <- oneOf setextHChars
many (char underlineChar)
@ -1730,6 +1740,7 @@ endline :: PandocMonad m => MarkdownParser m (F Inlines)
endline = try $ do
newline
notFollowedBy blankline
getState >>= guard . stateAllowLineBreaks
-- parse potential list-starts differently if in a list:
notFollowedBy (inList >> listStart)
guardDisabled Ext_lists_without_preceding_blankline <|> notFollowedBy listStart

13
test/command/5714.md Normal file
View file

@ -0,0 +1,13 @@
```
% pandoc -t native
# hi _a
b_
# hi _c
c
^D
[Header 1 ("hi-_a",[],[]) [Str "hi",Space,Str "_a"]
,Para [Str "b_"]
,Header 1 ("hi-_c",[],[]) [Str "hi",Space,Str "_c"]
,Para [Str "c"]]
```