aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2011-01-22 17:52:25 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2011-01-22 17:53:16 -0800
commitea5cd350042f31a66ee0d59e885d34598f9cc5a1 (patch)
treeee3c7b4a1ef6f8a19f56070c5c88e6fef019ef07 /src/Text/Pandoc.hs
parenta74010a051e4cd3fee7ebfb4a632d52bb32de61d (diff)
downloadpandoc-ea5cd350042f31a66ee0d59e885d34598f9cc5a1.tar.gz
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
Diffstat (limited to 'src/Text/Pandoc.hs')
-rw-r--r--src/Text/Pandoc.hs7
1 files changed, 7 insertions, 0 deletions
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