1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
5import Network.Wai.Handler.CGI
7import Control.Applicative ((<$>))
8import Data.Maybe (fromMaybe)
9import Network.HTTP.Types.Status (status200)
10import Network.HTTP.Types.Header (hContentType)
11import Network.HTTP.Types.URI (queryToQueryText)
13import Text.Pandoc.Writers.Math (defaultMathJaxURL)
14import Text.Pandoc.Highlighting (pygments)
15import Text.Pandoc.Readers (getReader, Reader(..))
16import Text.Pandoc.Writers (getWriter, Writer(..))
17import Text.Pandoc.Shared (tabFilter)
19import qualified Data.Text as T
20import Data.Text (Text)
27 let query = queryToQueryText $ queryString req
28 let getParam x = maybe (error $ T.unpack x ++ " parameter not set")
29 return $ lookup x query
30 text <- getParam "text" >>= checkLength . fromMaybe T.empty
31 fromFormat <- fromMaybe "" <$> getParam "from"
32 toFormat <- fromMaybe "" <$> getParam "to"
33 let reader = case getReader (T.unpack fromFormat) of
34 Right (TextReader r, es) -> r readerOpts{
35 readerExtensions = es }
36 _ -> error $ "could not find reader for "
37 ++ T.unpack fromFormat
38 let writer = case getWriter (T.unpack toFormat) of
39 Right (TextWriter w, es) -> w writerOpts{
40 writerExtensions = es }
41 _ -> error $ "could not find writer for " ++
43 let result = case runPure $ reader (tabFilter 4 text) >>= writer of
45 Left err -> error (show err)
46 let output = encode $ object [ T.pack "html" .= result
48 if fromFormat == "markdown_strict"
49 then T.pack "pandoc (strict)"
51 , T.pack "version" .= pandocVersion]
52 respond $ responseLBS status200 [(hContentType,"text/json; charset=UTF-8")] output
54checkLength :: Text -> IO Text
57 then error "exceeds length limit of 10,000 characters"
60writerOpts :: WriterOptions
61writerOpts = def { writerReferenceLinks = True,
62 writerEmailObfuscation = NoObfuscation,
63 writerHTMLMathMethod = MathJax (defaultMathJaxURL ++
64 "MathJax.js?config=TeX-AMS_CHTML-full"),
65 writerHighlightStyle = Just pygments }
67readerOpts :: 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