git.iko.soy/typeable/pandoc
on master help sign in
Added trypandoc flag to build trypandoc cgi executable.

Supporting files are in trypandoc/.

commit886cc0dd369c8975efe861d814a82b2d65343ede authorJohn MacFarlane <jgm@berkeley.edu> dateSun 17 Aug 2014, 16:11 (12 years ago) parentfa0d9a2
4 files changed+269
pandoc.cabal+18 trypandoc/Makefile+14 trypandoc/index.html+137 trypandoc/trypandoc.hs+100
pandoc.cabal+18
@@ -93,6 +93,9 @@ Extra-Source-Files:
9393 -- generated man pages (produced post-build)
9494 man/man1/pandoc.1
9595 man/man5/pandoc_markdown.5
96+ -- trypandoc
97+ trypandoc/Makefile
98+ trypandoc/index.html
9699 -- tests
97100 tests/bodybg.gif
98101 tests/*.native
@@ -184,6 +187,10 @@ Flag embed_data_files
184187 Description: Embed data files in binary for relocatable executable.
185188 Default: False
186189
190+Flag trypandoc
191+ Description: Build trypandoc cgi executable.
192+ Default: False
193+
187194Flag https
188195 Description: Enable support for downloading of resources over https.
189196 Default: True
@@ -352,6 +359,17 @@ Executable pandoc
352359 Main-Is: pandoc.hs
353360 Buildable: True
354361
362+Executable trypandoc
363+ Main-Is: trypandoc.hs
364+ Hs-Source-Dirs: trypandoc
365+ build-depends: base, aeson, pandoc, highlighting-kate,
366+ text, wai-extra, wai >= 0.3, http-types
367+ default-language: Haskell2010
368+ if flag(trypandoc)
369+ Buildable: True
370+ else
371+ Buildable: False
372+
355373-- NOTE: A trick in Setup.hs makes sure this won't be installed:
356374Executable make-pandoc-man-pages
357375 Main-Is: make-pandoc-man-pages.hs
trypandoc/Makefilenew file+14
@@ -0,0 +1,14 @@
1+CGIBIN=/home/website/cgi-bin
2+TRYPANDOC=/home/website/html/pandoc/try/
3+CGI=${CGIBIN}/trypandoc
4+BIN=../dist/build/trypandoc/trypandoc
5+
6+install: ${CGI} ${TRYPANDOC}/index.html
7+
8+${TRYPANDOC}/%: %
9+ cp $< $@ && chown website:www-data $@ && chmod a+r $@
10+
11+${CGI}: ${BIN}
12+ cp $< $@ && chown website:www-data $@ && chmod a+rx $@
13+
14+.PHONY: install
trypandoc/index.htmlnew file+137
@@ -0,0 +1,137 @@
1+<!doctype html>
2+<html lang="en">
3+<head>
4+ <meta charset="utf-8">
5+ <title>Try pandoc!</title>
6+ <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
7+ <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
8+ <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
9+ <script type="text/javascript">
10+(function($) { // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values
11+ $.QueryString = (function(a) {
12+ if (a == "") return {};
13+ var b = {};
14+ for (var i = 0; i < a.length; ++i)
15+ {
16+ var p=a[i].split('=');
17+ if (p.length != 2) continue;
18+ b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
19+ }
20+ return b;
21+ })(window.location.search.substr(1).split('&'))
22+})(jQuery);
23+
24+function newpage() {
25+ var input = $("#text").val();
26+ var from = $("#from").val();
27+ var to = $("#to").val();
28+ var href = window.location.href;
29+ window.location.href = href.replace(/([?].*)?$/,"?" + $.param({text: input, from: from, to: to}));
30+};
31+
32+function process(res) {
33+ $("#results").text(res.result);
34+ $("#version").text(res.version);
35+}
36+
37+$(document).ready(function() {
38+ var text = $.QueryString["text"];
39+ $("#text").val(text);
40+ var from = $.QueryString["from"] || "markdown";
41+ $("#from").val(from);
42+ var to = $.QueryString["to"] || "html";
43+ $("#to").val(to);
44+ if (text && text != "") {
45+ $.getJSON("http://johnmacfarlane.net/cgi-bin/trypandoc", { from: from, to: to, text: text }, process);
46+ };
47+ $("#convert").click(newpage);
48+});
49+ </script>
50+ <style type="text/css">
51+ h1 { margin-bottom: 1em; }
52+ body { margin: auto; }
53+ textarea { height: auto; width: 100%; font-family: monospace; margin-top: 15px; }
54+ div.alert { margin: 1em; }
55+ h3 { margin-top: 0; margin-bottom: 0; padding: 0; font-size: 100%; }
56+ pre#results { width: 100%; margin-top: 15px; }
57+ footer { color: #555; text-align: center; margin: 1em; }
58+ p.version { color: #555; }
59+ button#convert { vertical-align: bottom; }
60+ </style>
61+</head>
62+<body>
63+<div class="container">
64+ <div class="row">
65+ <h1>Try <a href="http://johnmacfarlane.net/pandoc/">pandoc</a>!</h1>
66+ </div>
67+ <div class="row">
68+ <div class="col-md-6">
69+ <label for="from">
70+ from
71+ </label>
72+ <select id="from">
73+ <option value="markdown" selected>Markdown</option>
74+ <option value="markdown_strict">Markdown/strict</option>
75+ <option value="markdown_phpextra">PHP Markdown Extra</option>
76+ <option value="markdown_github">Github Markdown</option>
77+ <option value="markdown_mmd">MultiMarkdown</option>
78+ <option value="rst">reStructuredText</option>
79+ <option value="textile">Textile</option>
80+ <option value="latex">LaTeX</option>
81+ <option value="html">HTML</option>
82+ <option value="docbook">DocBook</option>
83+ <option value="opml">OPML</option>
84+ <option value="org">Emacs Org Mode</option>
85+ <option value="t2t">Txt2Tags</option>
86+ <option value="mediawiki">MediaWiki</option>
87+ <option value="haddock">Haddock markup</option>
88+ </select>
89+ <br/>
90+ <textarea id="text" maxlength="3000" rows="15"></textarea>
91+ </div>
92+ <div class="col-md-6">
93+ <label for="to">
94+ to
95+ </label>
96+ <select id="to">
97+ <option value="html" selected>HTML</option>
98+ <option value="html5">HTML 5</option>
99+ <option value="markdown">Markdown</option>
100+ <option value="markdown_strict">Markdown/strict</option>
101+ <option value="markdown_phpextra">PHP Markdown Extra</option>
102+ <option value="markdown_github">Github Markdown</option>
103+ <option value="markdown_mmd">MultiMarkdown</option>
104+ <option value="rst">reStructuredText</option>
105+ <option value="asciidoc">AsciiDoc</option>
106+ <option value="textile">Textile</option>
107+ <option value="mediawiki">MediaWiki</option>
108+ <option value="dokuwiki">DokuWiki</option>
109+ <option value="org">Emacs Org Mode</option>
110+ <option value="latex">LaTeX</option>
111+ <option value="beamer">LaTeX Beamer</option>
112+ <option value="context">ConTeXt</option>
113+ <option value="man">Groff man</option>
114+ <option value="texinfo">Texinfo</option>
115+ <option value="docbook">DocBook</option>
116+ <option value="opml">OPML</option>
117+ <option value="icml">ICML</option>
118+ <option value="opendocument">OpenDocument</option>
119+ <option value="rtf">RTF</option>
120+ <option value="dzslides">DZSlides</option>
121+ <option value="slidy">Slidy</option>
122+ <option value="S5">S5</option>
123+ <option value="slideous">Slideous</option>
124+ </select>
125+ &nbsp;
126+ <button class="btn btn-primary btn-xs" id="convert">Convert</button>
127+ <br/>
128+ <pre id="results"></pre>
129+ </div>
130+ </div>
131+</div>
132+<footer>
133+ <p class="version">pandoc <span id="version"></span></p>
134+ <p>&copy; 2013&ndash;2014 <a href="http://johnmacfarlane.net">John MacFarlane</a></p>
135+</footer>
136+</body>
137+</html>
trypandoc/trypandoc.hsnew file+100
@@ -0,0 +1,100 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+module Main where
3+import Network.Wai.Handler.CGI
4+import Network.Wai
5+import Control.Applicative ((<$>))
6+import Data.Maybe (mapMaybe, fromMaybe)
7+import Network.HTTP.Types.Status (status200)
8+import Network.HTTP.Types.Header (hContentType)
9+import Network.HTTP.Types.URI (queryToQueryText)
10+import Text.Pandoc
11+import Text.Pandoc.Shared (tabFilter)
12+import Text.Highlighting.Kate (pygments)
13+import Data.Aeson
14+import qualified Data.Text as T
15+import Data.Text (Text)
16+
17+main :: IO ()
18+main = run app
19+
20+app :: Application
21+app req respond = do
22+ let query = queryToQueryText $ queryString req
23+ let getParam x = maybe (error $ T.unpack x ++ " paramater not set")
24+ return $ lookup x query
25+ text <- getParam "text" >>= checkLength . fromMaybe T.empty
26+ fromFormat <- fromMaybe "" <$> getParam "from"
27+ toFormat <- fromMaybe "" <$> getParam "to"
28+ reader <- maybe (error $ "could not find reader for " ++ T.unpack fromFormat) return
29+ $ lookup fromFormat fromFormats
30+ let writer = maybe (error $ "could not find writer for " ++ T.unpack toFormat) id
31+ $ lookup toFormat toFormats
32+ let result = T.pack $ writer $ reader $ tabFilter 4 $ T.unpack text
33+ let output = encode $ object [ T.pack "result" .= result
34+ , T.pack "name" .=
35+ if fromFormat == "markdown_strict"
36+ then T.pack "pandoc (strict)"
37+ else T.pack "pandoc"
38+ , T.pack "version" .= pandocVersion]
39+ respond $ responseLBS status200 [(hContentType,"text/json; charset=UTF-8")] output
40+
41+checkLength :: Text -> IO Text
42+checkLength t =
43+ if T.length t > 10000
44+ then error "exceeds length limit of 10,000 characters"
45+ else return t
46+
47+writerOpts :: WriterOptions
48+writerOpts = def { writerReferenceLinks = True,
49+ writerEmailObfuscation = NoObfuscation,
50+ writerHTMLMathMethod = MathJax "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
51+ writerHighlight = True,
52+ writerHighlightStyle = pygments }
53+
54+readerOpts :: ReaderOptions
55+readerOpts = def { readerParseRaw = True,
56+ readerSmart = True }
57+
58+fromFormats :: [(Text, String -> Pandoc)]
59+fromFormats = [
60+ ("native" , readNative)
61+ ,("json" , Text.Pandoc.readJSON readerOpts)
62+ ,("markdown" , readMarkdown readerOpts)
63+ ,("markdown_strict" , readMarkdown readerOpts{
64+ readerExtensions = strictExtensions,
65+ readerSmart = False })
66+ ,("markdown_phpextra" , readMarkdown readerOpts{
67+ readerExtensions = phpMarkdownExtraExtensions })
68+ ,("markdown_github" , readMarkdown readerOpts{
69+ readerExtensions = githubMarkdownExtensions })
70+ ,("markdown_mmd", readMarkdown readerOpts{
71+ readerExtensions = multimarkdownExtensions })
72+ ,("rst" , readRST readerOpts)
73+ ,("mediawiki" , readMediaWiki readerOpts)
74+ ,("docbook" , readDocBook readerOpts)
75+ ,("opml" , readOPML readerOpts)
76+ ,("t2t" , readTxt2TagsNoMacros readerOpts)
77+ ,("org" , readOrg readerOpts)
78+ ,("textile" , readTextile readerOpts) -- TODO : textile+lhs
79+ ,("html" , readHtml readerOpts)
80+ ,("latex" , readLaTeX readerOpts)
81+ ,("haddock" , readHaddock readerOpts)
82+ ]
83+
84+toFormats :: [(Text, Pandoc -> String)]
85+toFormats = mapMaybe (\(x,y) ->
86+ case y of
87+ PureStringWriter w -> Just (T.pack x, w writerOpts{
88+ writerExtensions =
89+ case x of
90+ "markdown_strict" -> strictExtensions
91+ "markdown_phpextra" -> phpMarkdownExtraExtensions
92+ "markdown_mmd" -> multimarkdownExtensions
93+ "markdown_github" -> githubMarkdownExtensions
94+ _ -> pandocExtensions
95+ })
96+ _ ->
97+ case x of
98+ "rtf" -> Just (T.pack x, writeRTF writerOpts)
99+ _ -> Nothing) writers
100+