Created
August 25, 2016 10:03
-
-
Save ehamberg/d08a22bdf2eb5e15264f34f0511f6bd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# Language ForeignFunctionInterface #-} | |
{-# Language OverloadedStrings #-} | |
module Main where | |
import Text.Pandoc | |
import GHCJS.Marshal | |
import GHCJS.Foreign.Callback | |
import JavaScript.Object | |
import JavaScript.Object.Internal (Object(..)) | |
convert :: String -> String | |
convert s = do | |
let readerOpts = def { readerSmart = True } | |
let Right doc = readMarkdown readerOpts s | |
let writerOptions = def { writerHtml5 = True } | |
writeHtmlString writerOptions doc | |
foreign import javascript unsafe "convert_ = $1" | |
js_set_convert :: Callback a -> IO () | |
main :: IO () | |
main = do | |
putStrLn "Haskell convert core starting..." | |
callback <- syncCallback1 ThrowWouldBlock $ \jsval -> do | |
let o = Object jsval | |
getProp "in" o | |
>>= fromJSValUnchecked | |
>>= pure . convert | |
>>= toJSVal | |
>>= \v -> setProp "out" v o | |
js_set_convert callback | |
putStr "Haskell convert callback initialized." |
Author
ehamberg
commented
Aug 25, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment