summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-11 00:06:03 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-11 00:06:03 -0800
commitf5c208230451c2f8446b639a4458a255e14778fb (patch)
tree6c433dac8a04895d102e43755c86996c12c4b2f2
parentdab645440af063b0c8e260bcda89080f986ad0e3 (diff)
parent167eeef6cb68d7cf4b5bd94f6543f84543df8c8c (diff)
Added JSON reader and writer.
The JSON reader is about 20x faster than the native reader. So this can be a good way to serialize a pandoc document.
-rw-r--r--README7
-rw-r--r--pandoc.cabal6
-rw-r--r--src/Text/Pandoc.hs3
3 files changed, 11 insertions, 5 deletions
diff --git a/README b/README
index b8692134a..03fa84547 100644
--- a/README
+++ b/README
@@ -140,8 +140,8 @@ Options
=======
`-f` *FORMAT*, `-r` *FORMAT*, `--from=`*FORMAT*, `--read=`*FORMAT*
-: Specify input format. *FORMAT* can be
- `native` (native Haskell), `markdown` (markdown or plain text),
+: Specify input format. *FORMAT* can be `native` (native Haskell),
+ `json` (JSON version of native AST), `markdown` (markdown),
`textile` (Textile), `rst` (reStructuredText), `html` (HTML),
or `latex` (LaTeX). If `+lhs` is appended to `markdown`, `rst`,
or `latex`, the input will be treated as literate Haskell source:
@@ -150,7 +150,8 @@ Options
`-t` *FORMAT*, `-w` *FORMAT*, `--to=`*FORMAT*, `--write=`*FORMAT*
: Specify output format. *FORMAT* can be `native` (native Haskell),
- `plain` (plain text), `markdown` (markdown), `rst` (reStructuredText),
+ `json` (JSON version of native AST), `plain` (plain text),
+ `markdown` (markdown), `rst` (reStructuredText),
`html` (HTML), `latex` (LaTeX), `context` (ConTeXt), `man` (groff man),
`mediawiki` (MediaWiki markup), `textile` (Textile), `org` (Emacs
Org-Mode), `texinfo` (GNU Texinfo), `docbook` (DocBook XML),
diff --git a/pandoc.cabal b/pandoc.cabal
index 08e2bc415..727bae405 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -169,7 +169,8 @@ Library
HTTP >= 4000.0.5, texmath >= 0.4, xml >= 1.3.5 && < 1.4,
random, extensible-exceptions,
citeproc-hs >= 0.3 && < 0.4,
- pandoc-types == 1.7.*
+ pandoc-types == 1.7.*,
+ json >= 0.4 && < 0.5
if impl(ghc >= 6.10)
Build-depends: base >= 4 && < 5, syb
else
@@ -240,7 +241,8 @@ Executable pandoc
HTTP >= 4000.0.5, texmath, xml >= 1.3.5 && < 1.4,
random, extensible-exceptions,
citeproc-hs >= 0.3 && < 0.4,
- pandoc-types == 1.7.*
+ pandoc-types == 1.7.*,
+ json >= 0.4 && < 0.5
if impl(ghc >= 6.10)
Build-depends: base >= 4 && < 5, syb
else
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs
index 0ac558663..7d3468461 100644
--- a/src/Text/Pandoc.hs
+++ b/src/Text/Pandoc.hs
@@ -130,6 +130,7 @@ import Text.Pandoc.Templates
import Text.Pandoc.Parsing
import Text.Pandoc.Shared
import Data.Version (showVersion)
+import Text.JSON.Generic
import Paths_pandoc (version)
-- | Version number of pandoc library.
@@ -139,6 +140,7 @@ pandocVersion = showVersion version
-- | Association list of formats and readers.
readers :: [(String, ParserState -> String -> Pandoc)]
readers = [("native" , \_ -> read)
+ ,("json" , \_ -> decodeJSON)
,("markdown" , readMarkdown)
,("markdown+lhs" , readMarkdown)
,("rst" , readRST)
@@ -153,6 +155,7 @@ readers = [("native" , \_ -> read)
-- binary writers, odt and epub).
writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
writers = [("native" , writeNative)
+ ,("json" , \_ -> encodeJSON)
,("html" , writeHtmlString)
,("html+lhs" , writeHtmlString)
,("s5" , writeHtmlString)