Skip to content

Instantly share code, notes, and snippets.

@funrep
Created June 28, 2013 14:45
Show Gist options
  • Save funrep/5885217 to your computer and use it in GitHub Desktop.
Save funrep/5885217 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
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 (readMarkdown, writeHtml, def)
import Data.Text (Text, unpack)
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 :: Text -> IO ()
publish md = do
file <- readMarkdown def $ unpack md
writeFile "posts/test.html" $ 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

test.hs:15:11:
No instance for (scotty-0.4.6:Web.Scotty.Action.Parsable Text)
arising from a use of param' Possible fix: add an instance declaration for (scotty-0.4.6:Web.Scotty.Action.Parsable Text) In a stmt of a 'do' block: md <- param "markdown" In the second argument of($)', namely
`do { md <- param "markdown";
liftIO $ publish md;
redirect "/archive" }'
In a stmt of a 'do' block:
post "/publish"
$ do { md <- param "markdown";
liftIO $ publish md;
redirect "/archive" }

test.hs:22:11:
Couldn't match expected type IO t0' with actual typeText.Pandoc.Definition.Pandoc'
In a stmt of a 'do' block: file <- readMarkdown def $ unpack md
In the expression:
do { file <- readMarkdown def $ unpack md;
writeFile "posts/test.html" $ writeHtml def file }
In an equation for `publish':
publish md
= do { file <- readMarkdown def $ unpack md;
writeFile "posts/test.html" $ writeHtml def file }

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