diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-07-01 22:29:04 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-07-01 22:29:04 -0700 |
commit | f3f557d988b69e83038a0756f3f72ab8334e2854 (patch) | |
tree | 64d648ac6348793eabcfb0204971084878af141e /src/Text | |
parent | 9009a7e4a8e8b9ddbf3327ae8a37f4bcb5df1b92 (diff) | |
download | pandoc-f3f557d988b69e83038a0756f3f72ab8334e2854.tar.gz |
Emit warning instead of failing on invalid YAML header.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 14 |
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 |