aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-07-01 22:29:04 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-07-01 22:29:04 -0700
commitf3f557d988b69e83038a0756f3f72ab8334e2854 (patch)
tree64d648ac6348793eabcfb0204971084878af141e
parent9009a7e4a8e8b9ddbf3327ae8a37f4bcb5df1b92 (diff)
downloadpandoc-f3f557d988b69e83038a0756f3f72ab8334e2854.tar.gz
Emit warning instead of failing on invalid YAML header.
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 8c836614f..e1d518350 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -227,20 +227,26 @@ pandocTitleBlock = try $ do
yamlTitleBlock :: MarkdownParser (F (Pandoc -> Pandoc))
yamlTitleBlock = try $ do
guardEnabled Ext_yaml_title_block
+ pos <- getPosition
string "---"
blankline
rawYaml <- unlines <$> manyTill anyLine stopLine
optional blanklines
opts <- stateOptions <$> getState
- return $ return $
- case Yaml.decode $ UTF8.fromString rawYaml of
- Just (Yaml.Object hashmap) ->
+ case Yaml.decodeEither $ UTF8.fromString rawYaml of
+ Right (Yaml.Object hashmap) -> return $ return $
H.foldrWithKey (\k v f ->
if ignorable k
then f
else B.setMeta (T.unpack k) (yamlToMeta opts v) . f)
id hashmap
- _ -> fail "Could not parse yaml object"
+ Left errStr -> do
+ addWarning (Just pos) $ "Could not parse YAML header: " ++
+ errStr
+ return $ return id
+ Right _ -> do
+ addWarning (Just pos) "YAML header is not an object"
+ return $ return id
-- ignore fields starting with _
ignorable :: Text -> Bool