git.iko.soy/typeable/pandoc
on master help sign in
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.

commitccf4e23ee12011e4c36b1f93e4f7a4d653a86a53 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 4 Feb 2019, 10:22 (8 years ago) parentca4d308
2 files changed+22−9
src/Text/Pandoc/Readers/Markdown.hs+10−9 test/command/5271.md+12
src/Text/Pandoc/Readers/Markdown.hs+10−9
@@ -284,21 +284,22 @@ nodeToKey _ = fail "Non-string key in YAML mappi
284284toMetaValue :: PandocMonad m
285285 => Text -> MarkdownParser m (F MetaValue)
286286toMetaValue x =
287− parseFromString' parser' (T.unpack x)
288− where parser' = (asInlines <$> ((trimInlinesF . mconcat)
289− <$> try (guard (not endsWithNewline)
290− *> manyTill inline eof)))
291− <|> (asBlocks <$> parseBlocks)
287+ -- Note: a standard quoted or unquoted YAML value will
288+ -- not end in a newline, but a "block" set off with
289+ -- `|` or `>` will.
290+ if (T.pack "\n") `T.isSuffixOf` x
291+ then parseFromString' (asBlocks <$> parseBlocks) (xstring <> "\n")
292+ else parseFromString'
293+ ((asInlines <$> try pInlines) <|> (asBlocks <$> parseBlocks))
294+ xstring
295+ where pInlines = trimInlinesF . mconcat <$> manyTill inline eof
292296 asBlocks p = do
293297 p' <- p
294298 return $ MetaBlocks (B.toList p')
295299 asInlines p = do
296300 p' <- p
297301 return $ MetaInlines (B.toList p')
298− endsWithNewline = T.pack "\n" `T.isSuffixOf` x
299− -- Note: a standard quoted or unquoted YAML value will
300− -- not end in a newline, but a "block" set off with
301− -- `|` or `>` will.
302+ xstring = T.unpack x
302303
303304checkBoolean :: Text -> Maybe Bool
304305checkBoolean t =
test/command/5271.mdnew file+12
@@ -0,0 +1,12 @@
1+```
2+% pandoc -f markdown -t native -s
3+---
4+abstract: |
5+ This is the abstract.
6+
7+ It consists of two paragraphs.
8+...
9+^D
10+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."]])]})
11+[]
12+```