Skip to content

Instantly share code, notes, and snippets.

@funrep
Created June 28, 2013 15:04
Show Gist options
  • Save funrep/5885357 to your computer and use it in GitHub Desktop.
Save funrep/5885357 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (writeFile)
import Web.Scotty (scotty, get, post, html, file, param, redirect)
import Text.Blaze.Html5 (Html)
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
import Text.Blaze.Html.Renderer.Text (renderHtml)
import Text.Pandoc (Pandoc, readMarkdown, writeHtml, def)
import Data.Text.Lazy.IO (writeFile)
import Control.Monad.Trans (liftIO)
main = scotty 3000 $ do
get "/" $ do
html $ renderHtml home
post "/publish" $ do
md <- param "markdown"
liftIO $ publish md
redirect "/archive"
get "/archive" $ file "/posts/test.html"
publish :: String -> IO ()
publish md = let file = readMarkdown def md in
writeFile "posts/test.html" $ renderHtml $ writeHtml def file
home :: Html
home = H.docTypeHtml $ do
H.html $ do
H.body $ do
H.form H.! A.method "post" H.! A.action "/publish" $ do
H.input H.! A.type_ "text" H.! A.name "markdown"
H.input H.! A.type_ "submit"
@funrep
Copy link
Author

funrep commented Jun 28, 2013

$ runhaskell test.hs
test.hs: /home/klrr/.cabal/lib/regex-pcre-builtin-0.94.4.6.8.31/ghc-7.4.1/HSregex-pcre-builtin-0.94.4.6.8.31.o: unknown symbol utf8_table4' test.hs: test.hs: unable to load packageregex-pcre-builtin-0.94.4.6.8.31'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment