1{-# LANGUAGE OverloadedStrings #-}
3import Network.Wai.Handler.CGI
5import Control.Applicative ((<$>))
6import Data.Maybe (fromMaybe)
7import Network.HTTP.Types.Status (status200)
8import Network.HTTP.Types.Header (hContentType)
9import Network.HTTP.Types.URI (queryToQueryText)
11import Text.Pandoc.Writers.Math (defaultMathJaxURL)
12import Text.Pandoc.Highlighting (pygments)
13import Text.Pandoc.Readers (getReader, Reader(..))
14import Text.Pandoc.Writers (getWriter, Writer(..))
15import Text.Pandoc.Shared (tabFilter)
17import qualified Data.Text as T
18import Data.Text (Text)
25 let query = queryToQueryText $ queryString req
26 let getParam x = maybe (error $ T.unpack x ++ " paramater not set")
27 return $ lookup x query
28 text <- getParam "text" >>= checkLength . fromMaybe T.empty
29 fromFormat <- fromMaybe "" <$> getParam "from"
30 toFormat <- fromMaybe "" <$> getParam "to"
31 let reader = case getReader (T.unpack fromFormat) of
32 Right (TextReader r, es) -> r readerOpts{
33 readerExtensions = es }
34 _ -> error $ "could not find reader for "
35 ++ T.unpack fromFormat
36 let writer = case getWriter (T.unpack toFormat) of
37 Right (TextWriter w, es) -> w writerOpts{
38 writerExtensions = es }
39 _ -> error $ "could not find writer for " ++
41 let result = case runPure $ reader (tabFilter 4 text) >>= writer of
43 Left err -> error (show err)
44 let output = encode $ object [ T.pack "html" .= result
46 if fromFormat == "markdown_strict"
47 then T.pack "pandoc (strict)"
49 , T.pack "version" .= pandocVersion]
50 respond $ responseLBS status200 [(hContentType,"text/json; charset=UTF-8")] output
52checkLength :: Text -> IO Text
55 then error "exceeds length limit of 10,000 characters"
58writerOpts :: WriterOptions
59writerOpts = def { writerReferenceLinks = True,
60 writerEmailObfuscation = NoObfuscation,
61 writerHTMLMathMethod = MathJax (defaultMathJaxURL ++
62 "MathJax.js?config=TeX-AMS_CHTML-full"),
63 writerHighlightStyle = Just pygments }
65readerOpts :: ReaderOptions
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list