Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to HsYAML-0.2 #5704

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ windows/*.wixobj
data/reference.docx
data/reference.odt
.stack-work
/dist-newstyle/
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ source-repository-package
type: git
location: https://github.com/jgm/pandoc-types
tag: 996a61018e406aa1e333e9085e84a04c83804c34

source-repository-package
type: git
location: https://github.com/vijayphoenix/HsYAML.git
tag: 9354f53c69e9178a8e7c5c17b47137e23d4179df
2 changes: 1 addition & 1 deletion pandoc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ library
http-types >= 0.8 && < 0.13,
case-insensitive >= 1.2 && < 1.3,
unicode-transforms >= 0.3 && < 0.4,
HsYAML >= 0.1.1.1 && < 0.2,
HsYAML >= 0.2,
ipynb >= 0.1 && < 0.2,
attoparsec >= 0.12 && < 0.14
if impl(ghc < 8.0)
Expand Down
23 changes: 12 additions & 11 deletions src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.YAML as YAML
import qualified Data.YAML.Event as YE
import System.FilePath (addExtension, takeExtension)
import Text.HTML.TagSoup
import Text.Pandoc.Builder (Blocks, Inlines)
Expand Down Expand Up @@ -244,22 +245,22 @@ yamlBsToMeta :: PandocMonad m => BS.ByteString -> MarkdownParser m (F Meta)
yamlBsToMeta bstr = do
pos <- getPosition
case YAML.decodeNode' YAML.failsafeSchemaResolver False False bstr of
Right ((YAML.Doc (YAML.Mapping _ o)):_) -> (fmap Meta) <$> yamlMap o
Right ((YAML.Doc (YAML.Mapping _ _ o)):_) -> (fmap Meta) <$> yamlMap o
Right [] -> return . return $ mempty
Right [YAML.Doc (YAML.Scalar YAML.SNull)] -> return . return $ mempty
Right [YAML.Doc (YAML.Scalar _ YAML.SNull)] -> return . return $ mempty
Right _ -> do
logMessage $
CouldNotParseYamlMetadata "not an object"
pos
return . return $ mempty
Left err' -> do
Left (_pos, err') -> do
logMessage $ CouldNotParseYamlMetadata
err' pos
return . return $ mempty

nodeToKey :: Monad m => YAML.Node -> m Text
nodeToKey (YAML.Scalar (YAML.SStr t)) = return t
nodeToKey (YAML.Scalar (YAML.SUnknown _ t)) = return t
nodeToKey :: Monad m => YAML.Node YE.Pos -> m Text
nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t
nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t
nodeToKey _ = fail "Non-string key in YAML mapping"

toMetaValue :: PandocMonad m
Expand Down Expand Up @@ -291,8 +292,8 @@ checkBoolean t =
else Nothing

yamlToMetaValue :: PandocMonad m
=> YAML.Node -> MarkdownParser m (F MetaValue)
yamlToMetaValue (YAML.Scalar x) =
=> YAML.Node YE.Pos-> MarkdownParser m (F MetaValue)
yamlToMetaValue (YAML.Scalar _ x) =
case x of
YAML.SStr t -> toMetaValue t
YAML.SBool b -> return $ return $ MetaBool b
Expand All @@ -303,16 +304,16 @@ yamlToMetaValue (YAML.Scalar x) =
Just b -> return $ return $ MetaBool b
Nothing -> toMetaValue t
YAML.SNull -> return $ return $ MetaString ""
yamlToMetaValue (YAML.Sequence _ xs) = do
yamlToMetaValue (YAML.Sequence _ _ xs) = do
xs' <- mapM yamlToMetaValue xs
return $ do
xs'' <- sequence xs'
return $ B.toMetaValue xs''
yamlToMetaValue (YAML.Mapping _ o) = fmap B.toMetaValue <$> yamlMap o
yamlToMetaValue (YAML.Mapping _ _ o) = fmap B.toMetaValue <$> yamlMap o
yamlToMetaValue _ = return $ return $ MetaString ""

yamlMap :: PandocMonad m
=> M.Map YAML.Node YAML.Node
=> M.Map (YAML.Node YE.Pos) (YAML.Node YE.Pos)
-> MarkdownParser m (F (M.Map String MetaValue))
yamlMap o = do
kvs <- forM (M.toList o) $ \(key, v) -> do
Expand Down
6 changes: 3 additions & 3 deletions src/Text/Pandoc/Translations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ instance FromJSON Term where
parseJSON invalid = Aeson.typeMismatch "Term" invalid

instance YAML.FromYAML Term where
parseYAML (YAML.Scalar (YAML.SStr t)) =
parseYAML (YAML.Scalar _ (YAML.SStr t)) =
case safeRead (T.unpack t) of
Just t' -> pure t'
Nothing -> fail $ "Invalid Term name " ++
Expand All @@ -99,12 +99,12 @@ instance FromJSON Translations where
instance YAML.FromYAML Translations where
parseYAML = YAML.withMap "Translations" $
\tr -> Translations .M.fromList <$> mapM addItem (M.toList tr)
where addItem (n@(YAML.Scalar (YAML.SStr k)), v) =
where addItem (n@(YAML.Scalar _ (YAML.SStr k)), v) =
case safeRead (T.unpack k) of
Nothing -> YAML.typeMismatch "Term" n
Just t ->
case v of
(YAML.Scalar (YAML.SStr s)) ->
(YAML.Scalar _ (YAML.SStr s)) ->
return (t, T.unpack (T.strip s))
n' -> YAML.typeMismatch "String" n'
addItem (n, _) = YAML.typeMismatch "String" n
Expand Down
4 changes: 4 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extra-deps:
commit: 6d62678ece91bbb4fe4f5a99695006e1d53c3bae
- git: https://github.com/tarleb/pandoc-types
commit: a087b0174a597b92c5fec4d633c46887c188b496
- git: https://github.com/vijayphoenix/HsYAML.git
commit: 9354f53c69e9178a8e7c5c17b47137e23d4179df
- git: https://github.com/vijayphoenix/HsYAML-aeson.git
commit: b4808ee9bd7e73eeafc7f6695e98a8c591d68f11
- ipynb-0.1
- cmark-gfm-0.2.0
- hslua-1.0.3.1
Expand Down