FastCGI Haskell script to use pandoc text conversion

1. Motivation

I am writing my mini-wiki. I want to be able to easily convert from markdowns to LATEX / HTML and vice versa. After some searching, I discovered Pandoc , which is written in Haskell, and that I can use the FastCGI module to run the Haskell program on my Apache server,

2. Problem / Question

I'm not sure how to use the protocol that I must use to send my FastCGI script I / O variables (POST / GET?) And how it is done exactly. Any ideas, suggestions, solutions?

3. Steps taken

3.1 Attempt

Here is what I have done so far (based on example code). Note that I have no experience with Haskell, and at the moment I donโ€™t have too much time to learn the language. I would just like to use the pandoc text format conversion tool.

module Main ( main ) where

import Control.Concurrent
import Network.FastCGI
import Text.Pandoc

--initialize Variables/ functions
fastcgiResult :: CGI CGIResult
markdownToHTML:: String -> String

--implement conversion function
markdownToHTML s = writeLaTeX defaultWriterOptions {writerReferenceLinks = True} (readMarkdown defaultParserState s)    

--main action
fastcgiResult = do
    setHeader "Content-type" "text/plain"
    n <- queryString
    output $ (markdownToHTML n)

main :: IO ()
main = runFastCGIConcurrent' forkIO 10 fastcgiResult

This code reads the line after the question mark in the request URL. But this is not a good solution, as some characters are omitted (for example, "#"), and spaces are replaced by "/ 20%".

Thanks in advance.

3.2 Network.CGI

The documentation found here. Under the heading โ€œEnter,โ€ there are a number of ways to enter data. Which one suits me?

It:

Get the value of an input variable, for example, from a form. If the variable has multiple values, the first is returned. Example:

query <- getInput "query"

, , HTML POST name='Joe', getInput? , Maybe String?

+3
1

fastCGI cgi, . CGI , fastCGI, , .

.

, :

" ," - , "", "". , , , Haskell . , "Maybe" , . ( "Just" "Nothing" ) , , , .

"" Maybe. :

maybe :: b -> (a -> b) -> Maybe a -> b

, "Maybe a" - , . - , , "Just v", "f v". - , , - "Nothing".

, "cgiMain" . "", "mn" โ€‹โ€‹ "Just" Joe Bloggs "), โ€‹โ€‹ (Nothing). ( , ).

, "" . , "mn" (Nothing), "inputForm" . "", URL-, "", "", , "Hello Joe Bloggs".

+2

All Articles