@@ -11,7 +11,7 @@
12Parse YAML/JSON metadata to 'Pandoc' 'Meta'.
12Parse YAML/JSON metadata to 'Pandoc' 'Meta'.
14−module Text.Pandoc.Readers.Metadata ( yamlBsToMeta ) where
14+module Text.Pandoc.Readers.Metadata ( yamlBsToMeta, yamlMap ) where
16import Control.Monad
16import Control.Monad
17import Control.Monad.Except (throwError)
17import Control.Monad.Except (throwError)
@@ -22,7 +22,6 @@ import qualified Data.Text as T
22import qualified Data.YAML as YAML
22import qualified Data.YAML as YAML
23import qualified Data.YAML.Event as YE
23import qualified Data.YAML.Event as YE
24import qualified Text.Pandoc.Builder as B
24import qualified Text.Pandoc.Builder as B
25−import Text.Pandoc.Builder (Blocks)
26import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
25import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
27import Text.Pandoc.Definition
26import Text.Pandoc.Definition
28import Text.Pandoc.Error
27import Text.Pandoc.Error
@@ -31,7 +30,7 @@ import Text.Pandoc.Parsing hiding (tableWith)
31import Text.Pandoc.Shared
30import Text.Pandoc.Shared
33yamlBsToMeta :: PandocMonad m
32yamlBsToMeta :: PandocMonad m
34− => ParserT Text ParserState m (F Blocks)
33+ => ParserT Text ParserState m (F MetaValue)
35 -> BL.ByteString
34 -> BL.ByteString
36 -> ParserT Text ParserState m (F Meta)
35 -> ParserT Text ParserState m (F Meta)
37yamlBsToMeta pBlocks bstr = do
36yamlBsToMeta pBlocks bstr = do
@@ -59,7 +58,7 @@ nodeToKey _ = throwError $ PandocParseError
59 "Non-string key in YAML mapping"
58 "Non-string key in YAML mapping"
61toMetaValue :: PandocMonad m
60toMetaValue :: PandocMonad m
62− => ParserT Text ParserState m (F Blocks)
61+ => ParserT Text ParserState m (F MetaValue)
64 -> ParserT Text ParserState m (F MetaValue)
63 -> ParserT Text ParserState m (F MetaValue)
65toMetaValue pBlocks x =
64toMetaValue pBlocks x =
@@ -67,18 +66,21 @@ toMetaValue pBlocks x =
67 -- not end in a newline, but a "block" set off with
66 -- not end in a newline, but a "block" set off with
68 -- `|` or `>` will.
67 -- `|` or `>` will.
69 if "\n" `T.isSuffixOf` x
68 if "\n" `T.isSuffixOf` x
70− then parseFromString' (asBlocks <$> pBlocks) (x <> "\n")
69+ then parseFromString' pBlocks (x <> "\n")
71 else parseFromString' pInlines x
70 else parseFromString' pInlines x
72 where pInlines = do
71 where pInlines = do
73 bs <- pBlocks
72 bs <- pBlocks
74 return $ do
73 return $ do
77− case B.toList bs' of
76+ case bs' of
78− [Plain ils] -> MetaInlines ils
79+ [Plain ils] -> MetaInlines ils
79− [Para ils] -> MetaInlines ils
80+ [Para ils] -> MetaInlines ils
80− xs -> MetaBlocks xs
81+ xs -> MetaBlocks xs
81− asBlocks p = MetaBlocks . B.toList <$> p
82+ _ -> bs'
83checkBoolean :: Text -> Maybe Bool
85checkBoolean :: Text -> Maybe Bool
84checkBoolean t
86checkBoolean t
@@ -87,7 +89,7 @@ checkBoolean t
87 | otherwise = Nothing
89 | otherwise = Nothing
89yamlToMetaValue :: PandocMonad m
91yamlToMetaValue :: PandocMonad m
90− => ParserT Text ParserState m (F Blocks)
92+ => ParserT Text ParserState m (F MetaValue)
91 -> YAML.Node YE.Pos
93 -> YAML.Node YE.Pos
92 -> ParserT Text ParserState m (F MetaValue)
94 -> ParserT Text ParserState m (F MetaValue)
93yamlToMetaValue pBlocks (YAML.Scalar _ x) =
95yamlToMetaValue pBlocks (YAML.Scalar _ x) =
@@ -112,7 +114,7 @@ yamlToMetaValue pBlocks (YAML.Mapping _ _ o) =
112yamlToMetaValue _ _ = return $ return $ MetaString ""
114yamlToMetaValue _ _ = return $ return $ MetaString ""
114yamlMap :: PandocMonad m
116yamlMap :: PandocMonad m
115− => ParserT Text ParserState m (F Blocks)
117+ => ParserT Text ParserState m (F MetaValue)
116 -> M.Map (YAML.Node YE.Pos) (YAML.Node YE.Pos)
118 -> M.Map (YAML.Node YE.Pos) (YAML.Node YE.Pos)
117 -> ParserT Text ParserState m (F (M.Map Text MetaValue))
119 -> ParserT Text ParserState m (F (M.Map Text MetaValue))
118yamlMap pBlocks o = do
120yamlMap pBlocks o = do
@@ -120,7 +122,7 @@ yamlMap pBlocks o = do
120 k <- nodeToKey key
122 k <- nodeToKey key
121 return (k, v)
123 return (k, v)
122 let kvs' = filter (not . ignorable . fst) kvs
124 let kvs' = filter (not . ignorable . fst) kvs
123− (fmap M.fromList . sequence) <$> mapM toMeta kvs'
125+ fmap M.fromList . sequence <$> mapM toMeta kvs'
125 ignorable t = "_" `T.isSuffixOf` t
127 ignorable t = "_" `T.isSuffixOf` t
126 toMeta (k, v) = do
128 toMeta (k, v) = do