aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-09 10:40:31 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-09 10:40:31 -0800
commit167eeef6cb68d7cf4b5bd94f6543f84543df8c8c (patch)
treea90560029d94da2de57228f4dce82df51e8fc575
parentbb609a85e3db8a25fbfac30858c8637eb6664fd6 (diff)
downloadpandoc-167eeef6cb68d7cf4b5bd94f6543f84543df8c8c.tar.gz
Added json format for reading and writing.
This is faster to parse than native.
-rw-r--r--README7
-rw-r--r--pandoc.cabal6
-rw-r--r--src/pandoc.hs11
3 files changed, 19 insertions, 5 deletions
diff --git a/README b/README
index 91ec5e70b..26859a81d 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 0be9f27bf..c2cc7268a 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -167,7 +167,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
@@ -238,7 +239,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/pandoc.hs b/src/pandoc.hs
index 3aa9a4ba8..e8220de34 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -29,6 +29,7 @@ Parses command-line options and calls the appropriate readers and
writers.
-}
module Main where
+import Text.JSON.Generic (encodeJSON, decodeJSON)
import Text.Pandoc
import Text.Pandoc.S5 (s5HeaderIncludes)
import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
@@ -83,6 +84,7 @@ wrapWords c = wrap' c c where
-- | Association list of formats and readers.
readers :: [(String, ParserState -> String -> Pandoc)]
readers = [("native" , readPandoc)
+ ,("json" , readJSON)
,("markdown" , readMarkdown)
,("markdown+lhs" , readMarkdown)
,("rst" , readRST)
@@ -97,9 +99,18 @@ readers = [("native" , readPandoc)
readPandoc :: ParserState -> String -> Pandoc
readPandoc _ = read
+-- | Reader for JSON version of Pandoc AST.
+readJSON :: ParserState -> String -> Pandoc
+readJSON _ = decodeJSON
+
+-- | Writer for JSON version of Pandoc AST.
+writeJSON :: WriterOptions -> Pandoc -> String
+writeJSON _ = encodeJSON
+
-- | Association list of formats and writers.
writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
writers = [("native" , writeNative)
+ ,("json" , writeJSON)
,("html" , writeHtmlString)
,("html+lhs" , writeHtmlString)
,("s5" , writeHtmlString)