Created
August 25, 2016 10:03
Revisions
-
ehamberg created this gist
Aug 25, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ {-# 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."