git.iko.soy/typeable/pandoc
on master help sign in
Use HsYAML-0.2.0.0
b64410fJohn MacFarlane
.gitignore+1
@@ -24,3 +24,4 @@ data/reference.docx
24data/reference.odt
24data/reference.odt
25.stack-work
25.stack-work
26cabal.project.local
26cabal.project.local
27+/dist-newstyle/
pandoc.cabal+1−1
@@ -421,7 +421,7 @@ library
421 http-types >= 0.8 && < 0.13,
421 http-types >= 0.8 && < 0.13,
422 case-insensitive >= 1.2 && < 1.3,
422 case-insensitive >= 1.2 && < 1.3,
423 unicode-transforms >= 0.3 && < 0.4,
423 unicode-transforms >= 0.3 && < 0.4,
424− HsYAML >= 0.1.1.1 && < 0.2,
424+ HsYAML >= 0.2 && < 0.3,
425 doclayout >= 0.1 && < 0.2,
425 doclayout >= 0.1 && < 0.2,
426 ipynb >= 0.1 && < 0.2,
426 ipynb >= 0.1 && < 0.2,
427 attoparsec >= 0.12 && < 0.14
427 attoparsec >= 0.12 && < 0.14
src/Text/Pandoc/Readers/Markdown.hs+12−11
@@ -28,6 +28,7 @@ import qualified Data.Set as Set
28import Data.Text (Text)
28import Data.Text (Text)
29import qualified Data.Text as T
29import qualified Data.Text as T
30import qualified Data.YAML as YAML
30import qualified Data.YAML as YAML
31+import qualified Data.YAML.Event as YE
31import System.FilePath (addExtension, takeExtension)
32import System.FilePath (addExtension, takeExtension)
32import Text.HTML.TagSoup
33import Text.HTML.TagSoup
33import Text.Pandoc.Builder (Blocks, Inlines)
34import Text.Pandoc.Builder (Blocks, Inlines)
@@ -244,22 +245,22 @@ yamlBsToMeta :: PandocMonad m => BS.ByteString -> MarkdownParser m (F Meta)
244yamlBsToMeta bstr = do
245yamlBsToMeta bstr = do
245 pos <- getPosition
246 pos <- getPosition
246 case YAML.decodeNode' YAML.failsafeSchemaResolver False False bstr of
247 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
248 Right [] -> return . return $ mempty
249 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
250 Right _ -> do
251 Right _ -> do
251 logMessage $
252 logMessage $
252 CouldNotParseYamlMetadata "not an object"
253 CouldNotParseYamlMetadata "not an object"
253 pos
254 pos
254 return . return $ mempty
255 return . return $ mempty
255− Left err' -> do
256+ Left (_pos, err') -> do
256 logMessage $ CouldNotParseYamlMetadata
257 logMessage $ CouldNotParseYamlMetadata
257 err' pos
258 err' pos
258 return . return $ mempty
259 return . return $ mempty
259
260
260−nodeToKey :: Monad m => YAML.Node -> m Text
261+nodeToKey :: Monad m => YAML.Node YE.Pos -> m Text
261−nodeToKey (YAML.Scalar (YAML.SStr t)) = return t
262+nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t
262−nodeToKey (YAML.Scalar (YAML.SUnknown _ t)) = return t
263+nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t
263nodeToKey _ = fail "Non-string key in YAML mapping"
264nodeToKey _ = fail "Non-string key in YAML mapping"
264
265
265toMetaValue :: PandocMonad m
266toMetaValue :: PandocMonad m
@@ -291,8 +292,8 @@ checkBoolean t =
291 else Nothing
292 else Nothing
292
293
293yamlToMetaValue :: PandocMonad m
294yamlToMetaValue :: PandocMonad m
294− => YAML.Node -> MarkdownParser m (F MetaValue)
295+ => YAML.Node YE.Pos-> MarkdownParser m (F MetaValue)
295−yamlToMetaValue (YAML.Scalar x) =
296+yamlToMetaValue (YAML.Scalar _ x) =
296 case x of
297 case x of
297 YAML.SStr t -> toMetaValue t
298 YAML.SStr t -> toMetaValue t
298 YAML.SBool b -> return $ return $ MetaBool b
299 YAML.SBool b -> return $ return $ MetaBool b
@@ -303,16 +304,16 @@ yamlToMetaValue (YAML.Scalar x) =
303 Just b -> return $ return $ MetaBool b
304 Just b -> return $ return $ MetaBool b
304 Nothing -> toMetaValue t
305 Nothing -> toMetaValue t
305 YAML.SNull -> return $ return $ MetaString ""
306 YAML.SNull -> return $ return $ MetaString ""
306−yamlToMetaValue (YAML.Sequence _ xs) = do
307+yamlToMetaValue (YAML.Sequence _ _ xs) = do
307 xs' <- mapM yamlToMetaValue xs
308 xs' <- mapM yamlToMetaValue xs
308 return $ do
309 return $ do
309 xs'' <- sequence xs'
310 xs'' <- sequence xs'
310 return $ B.toMetaValue xs''
311 return $ B.toMetaValue xs''
311−yamlToMetaValue (YAML.Mapping _ o) = fmap B.toMetaValue <$> yamlMap o
312+yamlToMetaValue (YAML.Mapping _ _ o) = fmap B.toMetaValue <$> yamlMap o
312yamlToMetaValue _ = return $ return $ MetaString ""
313yamlToMetaValue _ = return $ return $ MetaString ""
313
314
314yamlMap :: PandocMonad m
315yamlMap :: PandocMonad m
315− => M.Map YAML.Node YAML.Node
316+ => M.Map (YAML.Node YE.Pos) (YAML.Node YE.Pos)
316 -> MarkdownParser m (F (M.Map String MetaValue))
317 -> MarkdownParser m (F (M.Map String MetaValue))
317yamlMap o = do
318yamlMap o = do
318 kvs <- forM (M.toList o) $ \(key, v) -> do
319 kvs <- forM (M.toList o) $ \(key, v) -> do
src/Text/Pandoc/Translations.hs+8−6
@@ -76,7 +76,7 @@ instance FromJSON Term where
76 parseJSON invalid = Aeson.typeMismatch "Term" invalid
76 parseJSON invalid = Aeson.typeMismatch "Term" invalid
77
77
78instance YAML.FromYAML Term where
78instance YAML.FromYAML Term where
79− parseYAML (YAML.Scalar (YAML.SStr t)) =
79+ parseYAML (YAML.Scalar _ (YAML.SStr t)) =
80 case safeRead (T.unpack t) of
80 case safeRead (T.unpack t) of
81 Just t' -> pure t'
81 Just t' -> pure t'
82 Nothing -> fail $ "Invalid Term name " ++
82 Nothing -> fail $ "Invalid Term name " ++
@@ -99,12 +99,12 @@ instance FromJSON Translations where
99instance YAML.FromYAML Translations where
99instance YAML.FromYAML Translations where
100 parseYAML = YAML.withMap "Translations" $
100 parseYAML = YAML.withMap "Translations" $
101 \tr -> Translations .M.fromList <$> mapM addItem (M.toList tr)
101 \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) =
103 case safeRead (T.unpack k) of
103 case safeRead (T.unpack k) of
104 Nothing -> YAML.typeMismatch "Term" n
104 Nothing -> YAML.typeMismatch "Term" n
105 Just t ->
105 Just t ->
106 case v of
106 case v of
107− (YAML.Scalar (YAML.SStr s)) ->
107+ (YAML.Scalar _ (YAML.SStr s)) ->
108 return (t, T.unpack (T.strip s))
108 return (t, T.unpack (T.strip s))
109 n' -> YAML.typeMismatch "String" n'
109 n' -> YAML.typeMismatch "String" n'
110 addItem (n, _) = YAML.typeMismatch "String" n
110 addItem (n, _) = YAML.typeMismatch "String" n
@@ -115,6 +115,8 @@ lookupTerm t (Translations tm) = M.lookup t tm
115readTranslations :: String -> Either String Translations
115readTranslations :: String -> Either String Translations
116readTranslations s =
116readTranslations s =
117 case YAML.decodeStrict $ UTF8.fromString s of
117 case YAML.decodeStrict $ UTF8.fromString s of
118− Left err' -> Left err'
118+ Left (pos,err') -> Left $ err' ++
119+ " (line " ++ show (YAML.posLine pos) ++ " column " ++
120+ show (YAML.posColumn pos) ++ ")"
119− Right (t:_) -> Right t
121+ Right (t:_) -> Right t
120− Right [] -> Left "empty YAML document"
122+ Right [] -> Left "empty YAML document"
stack.yaml+2−1
@@ -25,7 +25,8 @@ extra-deps:
25- skylighting-core-0.8.2
25- skylighting-core-0.8.2
26- skylighting-0.8.2
26- skylighting-0.8.2
27- doclayout-0.1
27- doclayout-0.1
28+- HsYAML-0.2.0.0
28− #- doctemplates-0.6
29+#- doctemplates-0.6
29ghc-options:
30ghc-options:
30 "$locals": -fhide-source-paths -Wno-missing-home-modules
31 "$locals": -fhide-source-paths -Wno-missing-home-modules
31resolver: lts-13.17
32resolver: lts-13.17