Text.Pandoc: Added jsonFilter for easy construction of scripts.

Here's an example of its use:

-- removelinks.hs - removes links from document
import Text.Pandoc

main = interact $ jsonFilter $ bottomUp removeLink

removeLink :: Inline -> Inline
removeLink (Link xs _) = Emph xs
removeLink x = x
This commit is contained in:
John MacFarlane 2011-01-22 17:52:25 -08:00
parent a74010a051
commit ea5cd35004

View file

@ -106,6 +106,7 @@ module Text.Pandoc
, module Text.Pandoc.Templates
-- * Version
, pandocVersion
, jsonFilter
) where
import Text.Pandoc.Definition
@ -190,3 +191,9 @@ writers = [("native" , writeNative)
,("rtf" , writeRTF)
,("org" , writeOrg)
]
-- | Converts a transformation on the Pandoc AST into a function
-- that reads and writes a JSON-encoded string. This is useful
-- for writing small scripts.
jsonFilter :: (Pandoc -> Pandoc) -> String -> String
jsonFilter f = encodeJSON . f . decodeJSON