From ea5cd350042f31a66ee0d59e885d34598f9cc5a1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 22 Jan 2011 17:52:25 -0800 Subject: 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 --- src/Text/Pandoc.hs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index ed9fa3c27..0a43b4f30 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -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 -- cgit v1.2.3