pandoc-types 1.22.1 → 1.22.2
raw patch · 6 files changed
+63/−3 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable Text.Pandoc.Definition.Meta Text.Pandoc.Definition.Pandoc
+ Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable Text.Pandoc.Definition.MetaValue Text.Pandoc.Definition.Meta
+ Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable Text.Pandoc.Definition.MetaValue Text.Pandoc.Definition.MetaValue
+ Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable Text.Pandoc.Definition.MetaValue Text.Pandoc.Definition.Pandoc
+ Text.Pandoc.Walk: queryMetaValue' :: Monoid c => (MetaValue -> c) -> MetaValue -> c
+ Text.Pandoc.Walk: walkMetaValueM' :: (Monad f, Applicative f, Functor f) => (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue
Files
- changelog +6/−0
- pandoc-types.cabal +1/−1
- src/Text/Pandoc/Definition.hs +1/−1
- src/Text/Pandoc/JSON.hs +1/−1
- src/Text/Pandoc/Walk.hs +36/−0
- test/test-pandoc-types.hs +18/−0
changelog view
@@ -1,3 +1,9 @@+[1.22.2]++ * Use StrictData in Text.Pandoc.Definition.++ * Add Walkable Meta(Value) Pandoc instances (Travis Cardwell).+ [1.22.1] * Text.Pandoc.Builder: add simpleFigure, simpleFigureWith,
pandoc-types.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 Name: pandoc-types-version: 1.22.1+version: 1.22.2 Synopsis: Types for representing a structured document Description: @Text.Pandoc.Definition@ defines the 'Pandoc' data structure, which is used by pandoc to represent
src/Text/Pandoc/Definition.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings, DeriveDataTypeable, DeriveGeneric, FlexibleContexts, GeneralizedNewtypeDeriving, PatternGuards, CPP,- TemplateHaskell , PatternSynonyms, ViewPatterns #-}+ TemplateHaskell , PatternSynonyms, ViewPatterns, StrictData #-} {- Copyright (c) 2006-2019, John MacFarlane
src/Text/Pandoc/JSON.hs view
@@ -86,7 +86,7 @@ -- to stdout. -- -- For a straight transformation, use a function of type @a -> a@ or--- @a -> IO a@ where @a@ = 'Block', 'Inline','Pandoc', 'Meta', or 'MetaValue'.+-- @a -> IO a@ where @a@ = 'Block', 'Inline', 'Pandoc', 'Meta', or 'MetaValue'. -- -- If your transformation needs to be sensitive to the script's arguments, -- use a function of type @[String] -> a -> a@ (with @a@ constrained as above).
src/Text/Pandoc/Walk.hs view
@@ -98,6 +98,7 @@ , queryCitation , queryInline , queryMetaValue+ , queryMetaValue' , queryPandoc , walkBlockM , walkCaptionM@@ -109,12 +110,14 @@ , walkCitationM , walkInlineM , walkMetaValueM+ , walkMetaValueM' , walkPandocM ) where import Control.Applicative (Applicative ((<*>), pure), (<$>)) import Control.Monad ((>=>)) import Data.Functor.Identity (Identity (runIdentity))+import qualified Data.Map as M import Text.Pandoc.Definition import qualified Data.Traversable as T import Data.Traversable (Traversable)@@ -209,6 +212,14 @@ walkM = walkPandocM query = queryPandoc +instance Walkable Meta Pandoc where+ walkM f (Pandoc m bs) = Pandoc <$> f m <*> pure bs+ query f (Pandoc m _) = f m++instance Walkable MetaValue Pandoc where+ walkM f (Pandoc m bs) = Pandoc <$> walkM f m <*> pure bs+ query f (Pandoc m _) = query f m+ instance Walkable Pandoc Pandoc where walkM f = f query f = f@@ -236,9 +247,18 @@ walkM f (Meta metamap) = Meta <$> walkM f metamap query f (Meta metamap) = query f metamap +instance Walkable MetaValue Meta where+ walkM f (Meta metamap) =+ Meta . M.fromAscList <$> mapM (\(k, v) -> (,) k <$> walkM f v) (M.toAscList metamap)+ query f (Meta metamap) = M.foldMapWithKey (const $ query f) metamap+ -- -- Walk MetaValue --+instance Walkable MetaValue MetaValue where+ walkM f x = walkMetaValueM' f x >>= f+ query f x = f x <> queryMetaValue' f x+ instance Walkable Inline MetaValue where walkM = walkMetaValueM query = queryMetaValue@@ -513,6 +533,14 @@ walkMetaValueM f (MetaBlocks bs) = MetaBlocks <$> walkM f bs walkMetaValueM f (MetaMap m) = MetaMap <$> walkM f m +-- | Helper method to walk @'MetaValue'@ nodes nested below @'MetaValue'@ nodes.+walkMetaValueM' :: (Monad f, Applicative f, Functor f)+ => (MetaValue -> f MetaValue) -> MetaValue -> f MetaValue+walkMetaValueM' f (MetaMap m) =+ MetaMap . M.fromAscList <$> mapM (\(k, v) -> (,) k <$> walkM f v) (M.toAscList m)+walkMetaValueM' f (MetaList xs) = MetaList <$> mapM (walkM f) xs+walkMetaValueM' _ x = return x+ -- | Perform a query on elements nested below a @'MetaValue'@ element by -- querying all directly nested lists of @Inline@s, list of @Block@s, or -- lists or maps of @MetaValue@s.@@ -525,6 +553,14 @@ queryMetaValue f (MetaInlines xs) = query f xs queryMetaValue f (MetaBlocks bs) = query f bs queryMetaValue f (MetaMap m) = query f m++-- | Perform a query on @'MetaValue'@ elements nested below a @'MetaValue'@+-- element+queryMetaValue' :: Monoid c+ => (MetaValue -> c) -> MetaValue -> c+queryMetaValue' f (MetaMap m) = M.foldMapWithKey (const $ query f) m+queryMetaValue' f (MetaList xs) = mconcat $ map (query f) xs+queryMetaValue' _ _ = mempty -- | Helper method to walk to elements nested below @'Citation'@ nodes. --
test/test-pandoc-types.hs view
@@ -67,6 +67,14 @@ blocksTrans [Div _ xs] = xs blocksTrans xs = xs +metaValueTrans :: MetaValue -> MetaValue+metaValueTrans (MetaBool x) = MetaBool $ not x+metaValueTrans (MetaString xs) = MetaString $ T.toUpper xs+metaValueTrans x = x++metaTrans :: Meta -> Meta+metaTrans (Meta metamap) = Meta $ M.mapKeys T.toUpper metamap+ inlineQuery :: Inline -> Text inlineQuery (Str xs) = xs inlineQuery _ = ""@@ -81,7 +89,13 @@ blocksQuery :: [Block] -> Monoid.Sum Int blocksQuery = Monoid.Sum . length +metaValueQuery :: MetaValue -> Text+metaValueQuery (MetaString xs) = xs+metaValueQuery _ = "" +metaQuery :: Meta -> Monoid.Sum Int+metaQuery (Meta metamap) = Monoid.Sum $ M.size metamap+ prop_roundtrip :: Pandoc -> Bool prop_roundtrip doc = case decode $ encode doc :: (Maybe Pandoc) of Just doc' -> doc == doc'@@ -659,8 +673,12 @@ [ testGroup "Walk" [ testProperty "p_walk inlineTrans" (p_walk inlineTrans) , testProperty "p_walk blockTrans" (p_walk blockTrans)+ , testProperty "p_walk metaValueTrans" (p_walk metaValueTrans)+ , testProperty "p_walk metaTrans" (p_walk metaTrans) , testProperty "p_query inlineQuery" (p_query inlineQuery) , testProperty "p_query blockQuery" (p_query blockQuery)+ , testProperty "p_query metaValueQuery" (p_query metaValueQuery)+ , testProperty "p_query metaQuery" (p_query metaQuery) , testProperty "p_walkList inlinesTrans" (p_walkList inlinesTrans) , testProperty "p_queryList inlinesQuery" (p_queryList inlinesQuery) , testProperty "p_walkList blocksTrans" (p_walkList blocksTrans)