aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-02-04 10:22:02 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2019-02-04 10:22:02 -0800
commitccf4e23ee12011e4c36b1f93e4f7a4d653a86a53 (patch)
tree2052400796cc69df823a20194e7e29d223007c58 /src
parentca4d308b60472ab0dfb9186f5c999177ef3137da (diff)
downloadpandoc-ccf4e23ee12011e4c36b1f93e4f7a4d653a86a53.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 8d28abb2f..a602a5b4c 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -284,21 +284,22 @@ nodeToKey _ = fail "Non-string key in YAML mappi
toMetaValue :: PandocMonad m
=> Text -> MarkdownParser m (F MetaValue)
toMetaValue x =
- parseFromString' parser' (T.unpack x)
- where parser' = (asInlines <$> ((trimInlinesF . mconcat)
- <$> try (guard (not endsWithNewline)
- *> manyTill inline eof)))
- <|> (asBlocks <$> parseBlocks)
+ -- Note: a standard quoted or unquoted YAML value will
+ -- not end in a newline, but a "block" set off with
+ -- `|` or `>` will.
+ if (T.pack "\n") `T.isSuffixOf` x
+ then parseFromString' (asBlocks <$> parseBlocks) (xstring <> "\n")
+ else parseFromString'
+ ((asInlines <$> try pInlines) <|> (asBlocks <$> parseBlocks))
+ xstring
+ where pInlines = trimInlinesF . mconcat <$> manyTill inline eof
asBlocks p = do
p' <- p
return $ MetaBlocks (B.toList p')
asInlines p = do
p' <- p
return $ MetaInlines (B.toList p')
- endsWithNewline = T.pack "\n" `T.isSuffixOf` x
- -- Note: a standard quoted or unquoted YAML value will
- -- not end in a newline, but a "block" set off with
- -- `|` or `>` will.
+ xstring = T.unpack x
checkBoolean :: Text -> Maybe Bool
checkBoolean t =