How to bind Haskell Pandoc function to html selector with YesodWeb?

67 Views Asked by At

My usecase is the followin:

  • I have got a website setup with YesodWeb
  • I can write Text to one area
  • Pandoc transforms my text, and i receive a converted text in another textbox
  • The question: How can i bind my command to a html selector? i need to be able to give different commands to my Pandoc function depending on the selector.

My function in my.hs file:

pandocConverted :: String -> IO String 
pandocConverted input = do
    (Just hIn, Just hOut, _, _) <- createProcess (proc "pandoc" []) { std_in = CreatePipe, std_out = CreatePipe }
    hPutStr hIn input    
    converted  <- hGetContents hOut
    return converted

pandoc command line goes like this:

(proc "pandoc" ["-f", variable1, "-t", variable2]) "-f" is input e.g. "markup" "-t" is output e.g. "latex"

My selectors in chat.hamlet (html template):

<div style="float:right; margin-top:5px">
                <select id="selectorTo" onchange="getSelected(this)">
                    <option value="asciidoc">AsciiDoc</option>
                    <option value="context">ConTeXt</option>
                    <option value="docbook">DocBook</option>
                    <option value="dokuwiki">DokuWiki</option>
...

for output

and

<div style="float:left;"> 
                <p style="font-size:18px"> From: 
            <div style="float:right; margin-top:5px">
                <select id="selectorFrom" onchange="getSelected(this)">
                    <option value="docbook">DocBook
                    <option value="haddock">Haddock markup
                    <option value="html">HTML
                    <option value="latex">LaTeX
                    <option value="markdown" selected="">Markdown (pandoc)
... 

for input

I wrote this javascript. How do i get the variables back to my .hs file?

url = url.replace("http:", "ws:").replace("https:", "wss:");
conn = new WebSocket(url);

function getSelected(e) {
    var value = e.value;
    var selector = '';

    if(e.id == "selectorFrom"){
        selector = e.id;
    }
    if(e.id == "selectorTo"){
        selector = e.id;
    }
    console.log(selector + ": " + value);
    return (selector, value);
    conn.send(e.id, e.value);
 }

My conn.send(e.id, e.value) does not do anything. How would i receive the message on server side?

Please help me!

0

There are 0 best solutions below