git.iko.soy/typeable/pandoc
on master help sign in
Added json format for reading and writing.

This is faster to parse than native.

commit167eeef6cb68d7cf4b5bd94f6543f84543df8c8c authorJohn MacFarlane <jgm@berkeley.edu> dateThu 9 Dec 2010, 10:40 (16 years ago) parentbb609a8
3 files changed+19−5
README+4−3 pandoc.cabal+4−2 src/pandoc.hs+11
README+4−3
@@ -140,8 +140,8 @@ Options
140140=======
141141
142142`-f` *FORMAT*, `-r` *FORMAT*, `--from=`*FORMAT*, `--read=`*FORMAT*
143−: Specify input format. *FORMAT* can be
144− `native` (native Haskell), `markdown` (markdown or plain text),
143+: Specify input format. *FORMAT* can be `native` (native Haskell),
144+ `json` (JSON version of native AST), `markdown` (markdown),
145145 `textile` (Textile), `rst` (reStructuredText), `html` (HTML),
146146 or `latex` (LaTeX). If `+lhs` is appended to `markdown`, `rst`,
147147 or `latex`, the input will be treated as literate Haskell source:
@@ -150,7 +150,8 @@ Options
150150
151151`-t` *FORMAT*, `-w` *FORMAT*, `--to=`*FORMAT*, `--write=`*FORMAT*
152152: Specify output format. *FORMAT* can be `native` (native Haskell),
153− `plain` (plain text), `markdown` (markdown), `rst` (reStructuredText),
153+ `json` (JSON version of native AST), `plain` (plain text),
154+ `markdown` (markdown), `rst` (reStructuredText),
154155 `html` (HTML), `latex` (LaTeX), `context` (ConTeXt), `man` (groff man),
155156 `mediawiki` (MediaWiki markup), `textile` (Textile), `org` (Emacs
156157 Org-Mode), `texinfo` (GNU Texinfo), `docbook` (DocBook XML),
pandoc.cabal+4−2
@@ -167,7 +167,8 @@ Library
167167 HTTP >= 4000.0.5, texmath >= 0.4, xml >= 1.3.5 && < 1.4,
168168 random, extensible-exceptions,
169169 citeproc-hs >= 0.3 && < 0.4,
170− pandoc-types == 1.7.*
170+ pandoc-types == 1.7.*,
171+ json >= 0.4 && < 0.5
171172 if impl(ghc >= 6.10)
172173 Build-depends: base >= 4 && < 5, syb
173174 else
@@ -238,7 +239,8 @@ Executable pandoc
238239 HTTP >= 4000.0.5, texmath, xml >= 1.3.5 && < 1.4,
239240 random, extensible-exceptions,
240241 citeproc-hs >= 0.3 && < 0.4,
241− pandoc-types == 1.7.*
242+ pandoc-types == 1.7.*,
243+ json >= 0.4 && < 0.5
242244 if impl(ghc >= 6.10)
243245 Build-depends: base >= 4 && < 5, syb
244246 else
src/pandoc.hs+11
@@ -29,6 +29,7 @@ Parses command-line options and calls the appropriate readers and
2929writers.
3030-}
3131module Main where
32+import Text.JSON.Generic (encodeJSON, decodeJSON)
3233import Text.Pandoc
3334import Text.Pandoc.S5 (s5HeaderIncludes)
3435import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
@@ -83,6 +84,7 @@ wrapWords c = wrap' c c where
8384-- | Association list of formats and readers.
8485readers :: [(String, ParserState -> String -> Pandoc)]
8586readers = [("native" , readPandoc)
87+ ,("json" , readJSON)
8688 ,("markdown" , readMarkdown)
8789 ,("markdown+lhs" , readMarkdown)
8890 ,("rst" , readRST)
@@ -97,9 +99,18 @@ readers = [("native" , readPandoc)
9799readPandoc :: ParserState -> String -> Pandoc
98100readPandoc _ = read
99101
102+-- | Reader for JSON version of Pandoc AST.
103+readJSON :: ParserState -> String -> Pandoc
104+readJSON _ = decodeJSON
105+
106+-- | Writer for JSON version of Pandoc AST.
107+writeJSON :: WriterOptions -> Pandoc -> String
108+writeJSON _ = encodeJSON
109+
100110-- | Association list of formats and writers.
101111writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
102112writers = [("native" , writeNative)
113+ ,("json" , writeJSON)
103114 ,("html" , writeHtmlString)
104115 ,("html+lhs" , writeHtmlString)
105116 ,("s5" , writeHtmlString)