git.iko.soy/typeable/pandoc
on master help sign in
Emit warning instead of failing on invalid YAML header.
f3f557dJohn MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+10−4
@@ -227,20 +227,26 @@ pandocTitleBlock = try $ do
227yamlTitleBlock :: MarkdownParser (F (Pandoc -> Pandoc))
227yamlTitleBlock :: MarkdownParser (F (Pandoc -> Pandoc))
228yamlTitleBlock = try $ do
228yamlTitleBlock = try $ do
229 guardEnabled Ext_yaml_title_block
229 guardEnabled Ext_yaml_title_block
230+ pos <- getPosition
230 string "---"
231 string "---"
231 blankline
232 blankline
232 rawYaml <- unlines <$> manyTill anyLine stopLine
233 rawYaml <- unlines <$> manyTill anyLine stopLine
233 optional blanklines
234 optional blanklines
234 opts <- stateOptions <$> getState
235 opts <- stateOptions <$> getState
235− return $ return $
236− case Yaml.decode $ UTF8.fromString rawYaml of
236+ case Yaml.decodeEither $ UTF8.fromString rawYaml of
237− Just (Yaml.Object hashmap) ->
237+ Right (Yaml.Object hashmap) -> return $ return $
238 H.foldrWithKey (\k v f ->
238 H.foldrWithKey (\k v f ->
239 if ignorable k
239 if ignorable k
240 then f
240 then f
241 else B.setMeta (T.unpack k) (yamlToMeta opts v) . f)
241 else B.setMeta (T.unpack k) (yamlToMeta opts v) . f)
242 id hashmap
242 id hashmap
243− _ -> fail "Could not parse yaml object"
243+ Left errStr -> do
244+ addWarning (Just pos) $ "Could not parse YAML header: " ++
245+ errStr
246+ return $ return id
247+ Right _ -> do
248+ addWarning (Just pos) "YAML header is not an object"
249+ return $ return id
244
250
245-- ignore fields starting with _
251-- ignore fields starting with _
246ignorable :: Text -> Bool
252ignorable :: Text -> Bool