Markdown reader: add newline when parsing blocks in YAML.

Otherwise last block gets parsed as a Plain rather than
a Para.

This is a regression in pandoc 2.x.  This patch restores
pandoc 1.19 behavior.

Closes #5271.
This commit is contained in:
John MacFarlane 2019-02-04 10:22:02 -08:00
parent ca4d308b60
commit ccf4e23ee1
2 changed files with 22 additions and 9 deletions

View file

@ -284,21 +284,22 @@ nodeToKey _ = fail "Non-string key in YAML mappi
toMetaValue :: PandocMonad m toMetaValue :: PandocMonad m
=> Text -> MarkdownParser m (F MetaValue) => Text -> MarkdownParser m (F MetaValue)
toMetaValue x = toMetaValue x =
parseFromString' parser' (T.unpack x) -- Note: a standard quoted or unquoted YAML value will
where parser' = (asInlines <$> ((trimInlinesF . mconcat) -- not end in a newline, but a "block" set off with
<$> try (guard (not endsWithNewline) -- `|` or `>` will.
*> manyTill inline eof))) if (T.pack "\n") `T.isSuffixOf` x
<|> (asBlocks <$> parseBlocks) then parseFromString' (asBlocks <$> parseBlocks) (xstring <> "\n")
else parseFromString'
((asInlines <$> try pInlines) <|> (asBlocks <$> parseBlocks))
xstring
where pInlines = trimInlinesF . mconcat <$> manyTill inline eof
asBlocks p = do asBlocks p = do
p' <- p p' <- p
return $ MetaBlocks (B.toList p') return $ MetaBlocks (B.toList p')
asInlines p = do asInlines p = do
p' <- p p' <- p
return $ MetaInlines (B.toList p') return $ MetaInlines (B.toList p')
endsWithNewline = T.pack "\n" `T.isSuffixOf` x xstring = T.unpack x
-- Note: a standard quoted or unquoted YAML value will
-- not end in a newline, but a "block" set off with
-- `|` or `>` will.
checkBoolean :: Text -> Maybe Bool checkBoolean :: Text -> Maybe Bool
checkBoolean t = checkBoolean t =

12
test/command/5271.md Normal file
View file

@ -0,0 +1,12 @@
```
% pandoc -f markdown -t native -s
---
abstract: |
This is the abstract.
It consists of two paragraphs.
...
^D
Pandoc (Meta {unMeta = fromList [("abstract",MetaBlocks [Para [Str "This",Space,Str "is",Space,Str "the",Space,Str "abstract."],Para [Str "It",Space,Str "consists",Space,Str "of",Space,Str "two",Space,Str "paragraphs."]])]})
[]
```