Renamed processIn -> processWith, queryIn -> queryWith.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1521 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2009-01-24 19:58:26 +00:00
parent 066e1cfe90
commit 720e9ce3a5
4 changed files with 18 additions and 18 deletions

8
README
View file

@ -1242,7 +1242,7 @@ import Text.Pandoc
import Data.Char (toUpper)
transform :: [Inline] -> [Inline]
transform (Emph xs : ys) = processIn capStr xs ++ transform ys
transform (Emph xs : ys) = processWith capStr xs ++ transform ys
transform (x : ys) = x : transform ys
transform [] = []
@ -1255,19 +1255,19 @@ Here `transform` converts a whole list of `Inline` elements to another
such list. The key clause is
~~~ {.haskell}
transform (Emph xs : ys) = processIn capStr xs ++ transform ys
transform (Emph xs : ys) = processWith capStr xs ++ transform ys
~~~
This applies the `capStr` function recursively to all inlines in the
list of emphasized inlines and puts the transformed list in place
of the original. `capStr` is a simple `Inline` transformation that
capitalizes `Str` elements and leaves everything else alone. The
function `processIn`, defined in `Text.Pandoc.Definition`, uses some
function `processWith`, defined in `Text.Pandoc.Definition`, uses some
`Data.Generics` magic to apply its argument (here `capStr`) to every
`Inline` element in a list, including elements that are deeply buried in
other elements. Thus
processIn captStr [Str "one", Strong [Str "two", Space]] ==>
processWith captStr [Str "one", Strong [Str "two", Space]] ==>
[Str "ONE", Strong [Str "TWO", Space]]
There are other sample plugins in the `plugins` subdirectory of the

View file

@ -129,22 +129,22 @@ data Inline
deriving (Show, Eq, Read, Typeable, Data)
-- | Applies a transformation on @a@s to matching elements in a @b@.
processIn :: (Data a, Data b) => (a -> a) -> b -> b
processIn f = everywhere (mkT f)
processWith :: (Data a, Data b) => (a -> a) -> b -> b
processWith f = everywhere (mkT f)
-- | Like 'processIn', but with monadic transformations.
processInM :: (Monad m, Data a, Data b) => (a -> m a) -> b -> m b
processInM f = everywhereM (mkM f)
-- | Like 'processWith', but with monadic transformations.
processWithM :: (Monad m, Data a, Data b) => (a -> m a) -> b -> m b
processWithM f = everywhereM (mkM f)
-- | Runs a query on matching @a@ elements in a @c@.
queryIn :: (Data a, Data c) => (a -> [b]) -> c -> [b]
queryIn f = everything (++) ([] `mkQ` f)
queryWith :: (Data a, Data c) => (a -> [b]) -> c -> [b]
queryWith f = everything (++) ([] `mkQ` f)
{-# DEPRECATED processPandoc "Use processIn instead" #-}
{-# DEPRECATED processPandoc "Use processWith instead" #-}
processPandoc :: Data a => (a -> a) -> Pandoc -> Pandoc
processPandoc = processIn
processPandoc = processWith
{-# DEPRECATED queryPandoc "Use queryIn instead" #-}
{-# DEPRECATED queryPandoc "Use queryWith instead" #-}
queryPandoc :: Data a => (a -> [b]) -> Pandoc -> [b]
queryPandoc = queryIn
queryPandoc = queryWith

View file

@ -65,5 +65,5 @@ evaluatePlugin modsrc = do
throwError $ UnknownError $ "The plugin module must define a function 'transform'."
transformType <- typeOf "transform"
if "-> IO" `isInfixOf` transformType
then interpret "processInM transform" (as :: Pandoc -> IO Pandoc)
else interpret "return . (processIn transform)" (as :: Pandoc -> IO Pandoc)
then interpret "processWithM transform" (as :: Pandoc -> IO Pandoc)
else interpret "return . (processWith transform)" (as :: Pandoc -> IO Pandoc)

View file

@ -5,7 +5,7 @@ import Data.Char (toUpper)
-- This plugin changes emphasized text into CAPITALIZED TEXT.
transform :: [Inline] -> [Inline]
transform (Emph x : ys) = processIn capStr x ++ transform ys
transform (Emph x : ys) = processWith capStr x ++ transform ys
transform (x : ys) = x : transform ys
transform [] = []