@@ -40,6 +40,7 @@ import Text.Pandoc.Definition
4040import qualified Data.Text as T
4141import Data.Text (Text)
4242import qualified Data.Yaml as Yaml
43+import Data.Yaml (ParseException(..), YamlException(..), YamlMark(..))
4344import qualified Data.HashMap.Strict as H
4445import qualified Text.Pandoc.Builder as B
4546import qualified Text.Pandoc.UTF8 as UTF8
@@ -233,20 +234,32 @@ yamlTitleBlock = try $ do
233234 rawYaml <- unlines <$> manyTill anyLine stopLine
234235 optional blanklines
235236 opts <- stateOptions <$> getState
236− case Yaml.decodeEither $ UTF8.fromString rawYaml of
237+ case Yaml.decodeEither' $ UTF8.fromString rawYaml of
237238 Right (Yaml.Object hashmap) -> return $ return $
238239 H.foldrWithKey (\k v f ->
239240 if ignorable k
240241 then f
241242 else B.setMeta (T.unpack k) (yamlToMeta opts v) . f)
242243 id hashmap
243− Left errStr -> do
244− addWarning (Just pos) $ "Could not parse YAML header: " ++
245− errStr
246− return $ return id
247244 Right _ -> do
248245 addWarning (Just pos) "YAML header is not an object"
249246 return $ return id
247+ Left err' -> do
248+ case err' of
249+ InvalidYaml (Just YamlParseException{
250+ yamlProblem = problem
251+ , yamlContext = _ctxt
252+ , yamlProblemMark = Yaml.YamlMark {
253+ yamlLine = yline
254+ , yamlColumn = ycol
255+ }}) ->
256+ addWarning (Just $ setSourceLine
257+ (setSourceColumn pos (sourceColumn pos + ycol))
258+ (sourceLine pos + 1 + yline))
259+ $ "Could not parse YAML header: " ++ problem
260+ _ -> addWarning (Just pos)
261+ $ "Could not parse YAML header: " ++ show err'
262+ return $ return id
250263
251264-- ignore fields ending with _
252265ignorable :: Text -> Bool