    {-# LANGUAGE RelaxedPolyRec      #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE OverloadedStrings   #-}
    {- |
       Module      : Text.Pandoc.Readers.Metadata
       Copyright   : Copyright (C) 2006-2020 John MacFarlane
       License     : GNU GPL, version 2 or above

       Maintainer  : John MacFarlane <jgm@berkeley.edu>
       Stability   : alpha
       Portability : portable

    Parse YAML/JSON metadata to 'Pandoc' 'Meta'.
    -}
    module Text.Pandoc.Readers.Metadata ( yamlBsToMeta ) where

    import Control.Monad
    import Control.Monad.Except (throwError)
    import qualified Data.ByteString.Lazy as BL
    import qualified Data.Map as M
    import Data.Text (Text)
    import qualified Data.Text as T
    import qualified Data.YAML as YAML
    import qualified Data.YAML.Event as YE
    import qualified Text.Pandoc.Builder as B
    import Text.Pandoc.Builder (Blocks)
    import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
    import Text.Pandoc.Definition
    import Text.Pandoc.Error
    import Text.Pandoc.Logging
    import Text.Pandoc.Parsing hiding (tableWith)
    import Text.Pandoc.Shared

    yamlBsToMeta :: PandocMonad m
                 => ParserT Text ParserState m (F Blocks)
                 -> BL.ByteString
                 -> ParserT Text ParserState m (F Meta)
    yamlBsToMeta :: ParserT Text ParserState m (F Blocks)
    -> ByteString -> ParserT Text ParserState m (F Meta)
    yamlBsToMeta pBlocks :: ParserT Text ParserState m (F Blocks)
    pBlocks bstr :: ByteString
    bstr = do
      SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      case SchemaResolver
    -> Bool
    -> Bool
    -> ByteString
    -> Either (Pos, String) [Doc (Node Pos)]
    YAML.decodeNode' SchemaResolver
    YAML.failsafeSchemaResolver Bool
    False Bool
    False ByteString
    bstr of
           Right (YAML.Doc (YAML.Mapping _ _ o :: Mapping Pos
    o):_)
                    -> (Map Text MetaValue -> Meta)
    -> Future ParserState (Map Text MetaValue) -> F Meta
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Map Text MetaValue -> Meta
    Meta (Future ParserState (Map Text MetaValue) -> F Meta)
    -> ParsecT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    -> ParserT Text ParserState m (F Meta)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (F Blocks)
    -> Mapping Pos
    -> ParsecT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    forall (m :: * -> *).
    PandocMonad m =>
    ParserT Text ParserState m (F Blocks)
    -> Mapping Pos
    -> ParserT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    yamlMap ParserT Text ParserState m (F Blocks)
    pBlocks Mapping Pos
    o
           Right [] -> F Meta -> ParserT Text ParserState m (F Meta)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F Meta -> ParserT Text ParserState m (F Meta))
    -> (Meta -> F Meta) -> Meta -> ParserT Text ParserState m (F Meta)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Meta -> F Meta
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Meta -> ParserT Text ParserState m (F Meta))
    -> Meta -> ParserT Text ParserState m (F Meta)
    forall a b. (a -> b) -> a -> b
    $ Meta
    forall a. Monoid a => a
    mempty
           Right [YAML.Doc (YAML.Scalar _ YAML.SNull)]
                    -> F Meta -> ParserT Text ParserState m (F Meta)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F Meta -> ParserT Text ParserState m (F Meta))
    -> (Meta -> F Meta) -> Meta -> ParserT Text ParserState m (F Meta)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Meta -> F Meta
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Meta -> ParserT Text ParserState m (F Meta))
    -> Meta -> ParserT Text ParserState m (F Meta)
    forall a b. (a -> b) -> a -> b
    $ Meta
    forall a. Monoid a => a
    mempty
           Right _  -> do LogMessage -> ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParserT Text ParserState m ())
    -> LogMessage -> ParserT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    CouldNotParseYamlMetadata "not an object"
                                       SourcePos
    pos
                          F Meta -> ParserT Text ParserState m (F Meta)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F Meta -> ParserT Text ParserState m (F Meta))
    -> (Meta -> F Meta) -> Meta -> ParserT Text ParserState m (F Meta)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Meta -> F Meta
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Meta -> ParserT Text ParserState m (F Meta))
    -> Meta -> ParserT Text ParserState m (F Meta)
    forall a b. (a -> b) -> a -> b
    $ Meta
    forall a. Monoid a => a
    mempty
           Left (_pos :: Pos
    _pos, err' :: String
    err')
                    -> do LogMessage -> ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParserT Text ParserState m ())
    -> LogMessage -> ParserT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    CouldNotParseYamlMetadata
                                       (String -> Text
    T.pack String
    err') SourcePos
    pos
                          F Meta -> ParserT Text ParserState m (F Meta)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F Meta -> ParserT Text ParserState m (F Meta))
    -> (Meta -> F Meta) -> Meta -> ParserT Text ParserState m (F Meta)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Meta -> F Meta
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Meta -> ParserT Text ParserState m (F Meta))
    -> Meta -> ParserT Text ParserState m (F Meta)
    forall a b. (a -> b) -> a -> b
    $ Meta
    forall a. Monoid a => a
    mempty

    nodeToKey :: PandocMonad m
              => YAML.Node YE.Pos
              -> m Text
    nodeToKey :: Node Pos -> m Text
    nodeToKey (YAML.Scalar _ (YAML.SStr t :: Text
    t))       = Text -> m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    t
    nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t :: Text
    t)) = Text -> m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    t
    nodeToKey _  = PandocError -> m Text
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> m Text) -> PandocError -> m Text
    forall a b. (a -> b) -> a -> b
    $ Text -> PandocError
    PandocParseError
                                  "Non-string key in YAML mapping"

    toMetaValue :: PandocMonad m
                => ParserT Text ParserState m (F Blocks)
                -> Text
                -> ParserT Text ParserState m (F MetaValue)
    toMetaValue :: ParserT Text ParserState m (F Blocks)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    toMetaValue pBlocks :: ParserT Text ParserState m (F Blocks)
    pBlocks x :: Text
    x =
       -- Note: a standard quoted or unquoted YAML value will
       -- not end in a newline, but a "block" set off with
       -- `|` or `>` will.
       if "\n" Text -> Text -> Bool
    `T.isSuffixOf` Text
    x
          then ParserT Text ParserState m (F MetaValue)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' (F Blocks -> F MetaValue
    forall (f :: * -> *). Functor f => f Blocks -> f MetaValue
    asBlocks (F Blocks -> F MetaValue)
    -> ParserT Text ParserState m (F Blocks)
    -> ParserT Text ParserState m (F MetaValue)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (F Blocks)
    pBlocks) (Text
    x Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n")
          else ParserT Text ParserState m (F MetaValue)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m (F MetaValue)
    pInlines Text
    x
      where pInlines :: ParserT Text ParserState m (F MetaValue)
    pInlines = do
              F Blocks
    bs <- ParserT Text ParserState m (F Blocks)
    pBlocks
              F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ do
                Blocks
    bs' <- F Blocks
    bs
                MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $
                  case Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList Blocks
    bs' of
                    [Plain ils :: [Inline]
    ils] -> [Inline] -> MetaValue
    MetaInlines [Inline]
    ils
                    [Para ils :: [Inline]
    ils]  -> [Inline] -> MetaValue
    MetaInlines [Inline]
    ils
                    xs :: [Block]
    xs          -> [Block] -> MetaValue
    MetaBlocks [Block]
    xs
            asBlocks :: f Blocks -> f MetaValue
    asBlocks p :: f Blocks
    p = [Block] -> MetaValue
    MetaBlocks ([Block] -> MetaValue)
    -> (Blocks -> [Block]) -> Blocks -> MetaValue
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList (Blocks -> MetaValue) -> f Blocks -> f MetaValue
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> f Blocks
    p

    checkBoolean :: Text -> Maybe Bool
    checkBoolean :: Text -> Maybe Bool
    checkBoolean t :: Text
    t
      | Text
    t Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == String -> Text
    T.pack "true" Bool -> Bool -> Bool
    || Text
    t Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == String -> Text
    T.pack "True" Bool -> Bool -> Bool
    || Text
    t Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == String -> Text
    T.pack "TRUE" = Bool -> Maybe Bool
    forall a. a -> Maybe a
    Just Bool
    True
      | Text
    t Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == String -> Text
    T.pack "false" Bool -> Bool -> Bool
    || Text
    t Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == String -> Text
    T.pack "False" Bool -> Bool -> Bool
    || Text
    t Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == String -> Text
    T.pack "FALSE" = Bool -> Maybe Bool
    forall a. a -> Maybe a
    Just Bool
    False
      | Bool
    otherwise = Maybe Bool
    forall a. Maybe a
    Nothing

    yamlToMetaValue :: PandocMonad m
                    => ParserT Text ParserState m (F Blocks)
                    -> YAML.Node YE.Pos
                    -> ParserT Text ParserState m (F MetaValue)
    yamlToMetaValue :: ParserT Text ParserState m (F Blocks)
    -> Node Pos -> ParserT Text ParserState m (F MetaValue)
    yamlToMetaValue pBlocks :: ParserT Text ParserState m (F Blocks)
    pBlocks (YAML.Scalar _ x :: Scalar
    x) =
      case Scalar
    x of
           YAML.SStr t :: Text
    t       -> ParserT Text ParserState m (F Blocks)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *).
    PandocMonad m =>
    ParserT Text ParserState m (F Blocks)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    toMetaValue ParserT Text ParserState m (F Blocks)
    pBlocks Text
    t
           YAML.SBool b :: Bool
    b      -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ Bool -> MetaValue
    MetaBool Bool
    b
           YAML.SFloat d :: Double
    d     -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ Text -> MetaValue
    MetaString (Text -> MetaValue) -> Text -> MetaValue
    forall a b. (a -> b) -> a -> b
    $ Double -> Text
    forall a. Show a => a -> Text
    tshow Double
    d
           YAML.SInt i :: Integer
    i       -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ Text -> MetaValue
    MetaString (Text -> MetaValue) -> Text -> MetaValue
    forall a b. (a -> b) -> a -> b
    $ Integer -> Text
    forall a. Show a => a -> Text
    tshow Integer
    i
           YAML.SUnknown _ t :: Text
    t ->
             case Text -> Maybe Bool
    checkBoolean Text
    t of
               Just b :: Bool
    b        -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ Bool -> MetaValue
    MetaBool Bool
    b
               Nothing       -> ParserT Text ParserState m (F Blocks)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *).
    PandocMonad m =>
    ParserT Text ParserState m (F Blocks)
    -> Text -> ParserT Text ParserState m (F MetaValue)
    toMetaValue ParserT Text ParserState m (F Blocks)
    pBlocks Text
    t
           YAML.SNull        -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ Text -> MetaValue
    MetaString ""

    yamlToMetaValue pBlocks :: ParserT Text ParserState m (F Blocks)
    pBlocks (YAML.Sequence _ _ xs :: [Node Pos]
    xs) = do
      [F MetaValue]
    xs' <- (Node Pos -> ParserT Text ParserState m (F MetaValue))
    -> [Node Pos] -> ParsecT Text ParserState m [F MetaValue]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM (ParserT Text ParserState m (F Blocks)
    -> Node Pos -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *).
    PandocMonad m =>
    ParserT Text ParserState m (F Blocks)
    -> Node Pos -> ParserT Text ParserState m (F MetaValue)
    yamlToMetaValue ParserT Text ParserState m (F Blocks)
    pBlocks) [Node Pos]
    xs
      F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ do
        [MetaValue]
    xs'' <- [F MetaValue] -> Future ParserState [MetaValue]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    sequence [F MetaValue]
    xs'
        MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ [MetaValue] -> MetaValue
    forall a. ToMetaValue a => a -> MetaValue
    B.toMetaValue [MetaValue]
    xs''
    yamlToMetaValue pBlocks :: ParserT Text ParserState m (F Blocks)
    pBlocks (YAML.Mapping _ _ o :: Mapping Pos
    o) =
      (Map Text MetaValue -> MetaValue)
    -> Future ParserState (Map Text MetaValue) -> F MetaValue
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Map Text MetaValue -> MetaValue
    forall a. ToMetaValue a => a -> MetaValue
    B.toMetaValue (Future ParserState (Map Text MetaValue) -> F MetaValue)
    -> ParsecT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    -> ParserT Text ParserState m (F MetaValue)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (F Blocks)
    -> Mapping Pos
    -> ParsecT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    forall (m :: * -> *).
    PandocMonad m =>
    ParserT Text ParserState m (F Blocks)
    -> Mapping Pos
    -> ParserT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    yamlMap ParserT Text ParserState m (F Blocks)
    pBlocks Mapping Pos
    o
    yamlToMetaValue _ _ = F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (F MetaValue -> ParserT Text ParserState m (F MetaValue))
    -> F MetaValue -> ParserT Text ParserState m (F MetaValue)
    forall a b. (a -> b) -> a -> b
    $ MetaValue -> F MetaValue
    forall (m :: * -> *) a. Monad m => a -> m a
    return (MetaValue -> F MetaValue) -> MetaValue -> F MetaValue
    forall a b. (a -> b) -> a -> b
    $ Text -> MetaValue
    MetaString ""

    yamlMap :: PandocMonad m
            => ParserT Text ParserState m (F Blocks)
            -> M.Map (YAML.Node YE.Pos) (YAML.Node YE.Pos)
            -> ParserT Text ParserState m (F (M.Map Text MetaValue))
    yamlMap :: ParserT Text ParserState m (F Blocks)
    -> Mapping Pos
    -> ParserT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    yamlMap pBlocks :: ParserT Text ParserState m (F Blocks)
    pBlocks o :: Mapping Pos
    o = do
        [(Text, Node Pos)]
    kvs <- [(Node Pos, Node Pos)]
    -> ((Node Pos, Node Pos)
        -> ParsecT Text ParserState m (Text, Node Pos))
    -> ParsecT Text ParserState m [(Text, Node Pos)]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    t a -> (a -> m b) -> m (t b)
    forM (Mapping Pos -> [(Node Pos, Node Pos)]
    forall k a. Map k a -> [(k, a)]
    M.toList Mapping Pos
    o) (((Node Pos, Node Pos)
      -> ParsecT Text ParserState m (Text, Node Pos))
     -> ParsecT Text ParserState m [(Text, Node Pos)])
    -> ((Node Pos, Node Pos)
        -> ParsecT Text ParserState m (Text, Node Pos))
    -> ParsecT Text ParserState m [(Text, Node Pos)]
    forall a b. (a -> b) -> a -> b
    $ \(key :: Node Pos
    key, v :: Node Pos
    v) -> do
                 Text
    k <- Node Pos -> ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => Node Pos -> m Text
    nodeToKey Node Pos
    key
                 (Text, Node Pos) -> ParsecT Text ParserState m (Text, Node Pos)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    k, Node Pos
    v)
        let kvs' :: [(Text, Node Pos)]
    kvs' = ((Text, Node Pos) -> Bool)
    -> [(Text, Node Pos)] -> [(Text, Node Pos)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Bool -> Bool
    not (Bool -> Bool)
    -> ((Text, Node Pos) -> Bool) -> (Text, Node Pos) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Bool
    ignorable (Text -> Bool)
    -> ((Text, Node Pos) -> Text) -> (Text, Node Pos) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, Node Pos) -> Text
    forall a b. (a, b) -> a
    fst) [(Text, Node Pos)]
    kvs
        (([(Text, MetaValue)] -> Map Text MetaValue)
    -> Future ParserState [(Text, MetaValue)]
    -> Future ParserState (Map Text MetaValue)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap [(Text, MetaValue)] -> Map Text MetaValue
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList (Future ParserState [(Text, MetaValue)]
     -> Future ParserState (Map Text MetaValue))
    -> ([Future ParserState (Text, MetaValue)]
        -> Future ParserState [(Text, MetaValue)])
    -> [Future ParserState (Text, MetaValue)]
    -> Future ParserState (Map Text MetaValue)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Future ParserState (Text, MetaValue)]
    -> Future ParserState [(Text, MetaValue)]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    sequence) ([Future ParserState (Text, MetaValue)]
     -> Future ParserState (Map Text MetaValue))
    -> ParsecT
         Text ParserState m [Future ParserState (Text, MetaValue)]
    -> ParserT
         Text ParserState m (Future ParserState (Map Text MetaValue))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((Text, Node Pos)
     -> ParsecT
          Text ParserState m (Future ParserState (Text, MetaValue)))
    -> [(Text, Node Pos)]
    -> ParsecT
         Text ParserState m [Future ParserState (Text, MetaValue)]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM (Text, Node Pos)
    -> ParsecT
         Text ParserState m (Future ParserState (Text, MetaValue))
    forall a.
    (a, Node Pos)
    -> ParsecT Text ParserState m (Future ParserState (a, MetaValue))
    toMeta [(Text, Node Pos)]
    kvs'
      where
        ignorable :: Text -> Bool
    ignorable t :: Text
    t = "_" Text -> Text -> Bool
    `T.isSuffixOf` Text
    t
        toMeta :: (a, Node Pos)
    -> ParsecT Text ParserState m (Future ParserState (a, MetaValue))
    toMeta (k :: a
    k, v :: Node Pos
    v) = do
          F MetaValue
    fv <- ParserT Text ParserState m (F Blocks)
    -> Node Pos -> ParserT Text ParserState m (F MetaValue)
    forall (m :: * -> *).
    PandocMonad m =>
    ParserT Text ParserState m (F Blocks)
    -> Node Pos -> ParserT Text ParserState m (F MetaValue)
    yamlToMetaValue ParserT Text ParserState m (F Blocks)
    pBlocks Node Pos
    v
          Future ParserState (a, MetaValue)
    -> ParsecT Text ParserState m (Future ParserState (a, MetaValue))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Future ParserState (a, MetaValue)
     -> ParsecT Text ParserState m (Future ParserState (a, MetaValue)))
    -> Future ParserState (a, MetaValue)
    -> ParsecT Text ParserState m (Future ParserState (a, MetaValue))
    forall a b. (a -> b) -> a -> b
    $ do
            MetaValue
    v' <- F MetaValue
    fv
            (a, MetaValue) -> Future ParserState (a, MetaValue)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a
    k, MetaValue
    v')