git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Better error messages for yaml headers.
commite973bbbbc8330ded96e2ed7aec678bd90f014ae5 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 2 Jul 2013, 09:23 (13 years ago) parentd39f527
3 files changed+21−6
pandoc.cabal+1−1 src/Text/Pandoc/Parsing.hs+2 src/Text/Pandoc/Readers/Markdown.hs+18−5
pandoc.cabal+1−1
@@ -259,7 +259,7 @@ Library
259259 blaze-markup >= 0.5.1 && < 0.6,
260260 attoparsec >= 0.10 && < 0.11,
261261 stringable >= 0.1 && < 0.2,
262− yaml >= 0.8 && < 0.9,
262+ yaml >= 0.8.3 && < 0.9,
263263 vector >= 0.10 && < 0.11,
264264 hslua >= 0.3 && < 0.4
265265 if flag(embed_data_files)
src/Text/Pandoc/Parsing.hs+2
@@ -141,6 +141,8 @@ module Text.Pandoc.Parsing ( (>>~),
141141 setPosition,
142142 sourceColumn,
143143 sourceLine,
144+ setSourceColumn,
145+ setSourceLine,
144146 newPos,
145147 token
146148 )
src/Text/Pandoc/Readers/Markdown.hs+18−5
@@ -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