git.iko.soy/typeable/pandoc
on master help sign in
Use HsYAML-0.2.0.0

Most of this is due to @vijayphoenix (#5704), but it needed some revisions to integrate with current master, and to use the released HsYAML. Closes #5704.

commitb64410ff9ce64d6a2c7e09b43694b6f4245f9129 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 22 Sep 2019, 10:15 (7 years ago) parentfc44371
5 files changed+24−19
.gitignore+1 pandoc.cabal+1−1 src/Text/Pandoc/Readers/Markdown.hs+12−11 src/Text/Pandoc/Translations.hs+8−6 stack.yaml+2−1
.gitignore+1
@@ -24,3 +24,4 @@ data/reference.docx
2424data/reference.odt
2525.stack-work
2626cabal.project.local
27+/dist-newstyle/
pandoc.cabal+1−1
@@ -421,7 +421,7 @@ library
421421 http-types >= 0.8 && < 0.13,
422422 case-insensitive >= 1.2 && < 1.3,
423423 unicode-transforms >= 0.3 && < 0.4,
424− HsYAML >= 0.1.1.1 && < 0.2,
424+ HsYAML >= 0.2 && < 0.3,
425425 doclayout >= 0.1 && < 0.2,
426426 ipynb >= 0.1 && < 0.2,
427427 attoparsec >= 0.12 && < 0.14
src/Text/Pandoc/Readers/Markdown.hs+12−11
@@ -28,6 +28,7 @@ import qualified Data.Set as Set
2828import Data.Text (Text)
2929import qualified Data.Text as T
3030import qualified Data.YAML as YAML
31+import qualified Data.YAML.Event as YE
3132import System.FilePath (addExtension, takeExtension)
3233import Text.HTML.TagSoup
3334import Text.Pandoc.Builder (Blocks, Inlines)
@@ -244,22 +245,22 @@ yamlBsToMeta :: PandocMonad m => BS.ByteString -> MarkdownParser m (F Meta)
244245yamlBsToMeta bstr = do
245246 pos <- getPosition
246247 case YAML.decodeNode' YAML.failsafeSchemaResolver False False bstr of
247− Right ((YAML.Doc (YAML.Mapping _ o)):_) -> (fmap Meta) <$> yamlMap o
248+ Right ((YAML.Doc (YAML.Mapping _ _ o)):_) -> (fmap Meta) <$> yamlMap o
248249 Right [] -> return . return $ mempty
249− Right [YAML.Doc (YAML.Scalar YAML.SNull)] -> return . return $ mempty
250+ Right [YAML.Doc (YAML.Scalar _ YAML.SNull)] -> return . return $ mempty
250251 Right _ -> do
251252 logMessage $
252253 CouldNotParseYamlMetadata "not an object"
253254 pos
254255 return . return $ mempty
255− Left err' -> do
256+ Left (_pos, err') -> do
256257 logMessage $ CouldNotParseYamlMetadata
257258 err' pos
258259 return . return $ mempty
259260
260−nodeToKey :: Monad m => YAML.Node -> m Text
261−nodeToKey (YAML.Scalar (YAML.SStr t)) = return t
262−nodeToKey (YAML.Scalar (YAML.SUnknown _ t)) = return t
261+nodeToKey :: Monad m => YAML.Node YE.Pos -> m Text
262+nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t
263+nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t
263264nodeToKey _ = fail "Non-string key in YAML mapping"
264265
265266toMetaValue :: PandocMonad m
@@ -291,8 +292,8 @@ checkBoolean t =
291292 else Nothing
292293
293294yamlToMetaValue :: PandocMonad m
294− => YAML.Node -> MarkdownParser m (F MetaValue)
295−yamlToMetaValue (YAML.Scalar x) =
295+ => YAML.Node YE.Pos-> MarkdownParser m (F MetaValue)
296+yamlToMetaValue (YAML.Scalar _ x) =
296297 case x of
297298 YAML.SStr t -> toMetaValue t
298299 YAML.SBool b -> return $ return $ MetaBool b
@@ -303,16 +304,16 @@ yamlToMetaValue (YAML.Scalar x) =
303304 Just b -> return $ return $ MetaBool b
304305 Nothing -> toMetaValue t
305306 YAML.SNull -> return $ return $ MetaString ""
306−yamlToMetaValue (YAML.Sequence _ xs) = do
307+yamlToMetaValue (YAML.Sequence _ _ xs) = do
307308 xs' <- mapM yamlToMetaValue xs
308309 return $ do
309310 xs'' <- sequence xs'
310311 return $ B.toMetaValue xs''
311−yamlToMetaValue (YAML.Mapping _ o) = fmap B.toMetaValue <$> yamlMap o
312+yamlToMetaValue (YAML.Mapping _ _ o) = fmap B.toMetaValue <$> yamlMap o
312313yamlToMetaValue _ = return $ return $ MetaString ""
313314
314315yamlMap :: PandocMonad m
315− => M.Map YAML.Node YAML.Node
316+ => M.Map (YAML.Node YE.Pos) (YAML.Node YE.Pos)
316317 -> MarkdownParser m (F (M.Map String MetaValue))
317318yamlMap o = do
318319 kvs <- forM (M.toList o) $ \(key, v) -> do
src/Text/Pandoc/Translations.hs+8−6
@@ -76,7 +76,7 @@ instance FromJSON Term where
7676 parseJSON invalid = Aeson.typeMismatch "Term" invalid
7777
7878instance YAML.FromYAML Term where
79− parseYAML (YAML.Scalar (YAML.SStr t)) =
79+ parseYAML (YAML.Scalar _ (YAML.SStr t)) =
8080 case safeRead (T.unpack t) of
8181 Just t' -> pure t'
8282 Nothing -> fail $ "Invalid Term name " ++
@@ -99,12 +99,12 @@ instance FromJSON Translations where
9999instance YAML.FromYAML Translations where
100100 parseYAML = YAML.withMap "Translations" $
101101 \tr -> Translations .M.fromList <$> mapM addItem (M.toList tr)
102− where addItem (n@(YAML.Scalar (YAML.SStr k)), v) =
102+ where addItem (n@(YAML.Scalar _ (YAML.SStr k)), v) =
103103 case safeRead (T.unpack k) of
104104 Nothing -> YAML.typeMismatch "Term" n
105105 Just t ->
106106 case v of
107− (YAML.Scalar (YAML.SStr s)) ->
107+ (YAML.Scalar _ (YAML.SStr s)) ->
108108 return (t, T.unpack (T.strip s))
109109 n' -> YAML.typeMismatch "String" n'
110110 addItem (n, _) = YAML.typeMismatch "String" n
@@ -115,6 +115,8 @@ lookupTerm t (Translations tm) = M.lookup t tm
115115readTranslations :: String -> Either String Translations
116116readTranslations s =
117117 case YAML.decodeStrict $ UTF8.fromString s of
118− Left err' -> Left err'
119− Right (t:_) -> Right t
120− Right [] -> Left "empty YAML document"
118+ Left (pos,err') -> Left $ err' ++
119+ " (line " ++ show (YAML.posLine pos) ++ " column " ++
120+ show (YAML.posColumn pos) ++ ")"
121+ Right (t:_) -> Right t
122+ Right [] -> Left "empty YAML document"
stack.yaml+2−1
@@ -25,7 +25,8 @@ extra-deps:
2525- skylighting-core-0.8.2
2626- skylighting-0.8.2
2727- doclayout-0.1
28− #- doctemplates-0.6
28+- HsYAML-0.2.0.0
29+#- doctemplates-0.6
2930ghc-options:
3031 "$locals": -fhide-source-paths -Wno-missing-home-modules
3132resolver: lts-13.17