Last active
August 29, 2015 14:17
-
-
Save capicue/9565df3f0850a24a6ad3 to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"version": "0.0.0", | |
"summary": "Markdown Preview", | |
"description": "A quick markdown previewer in Elm.", | |
"license": "BSD3", | |
"source-directories": [ | |
"." | |
], | |
"exposed-modules": [], | |
"dependencies": { | |
"elm-lang/core": "1.0.0 <= v < 2.0.0", | |
"evancz/elm-html": "1.0.0 <= v < 2.0.0" | |
}, | |
"repository": "https://gist.github.com/capicue/9565df3f0850a24a6ad3" | |
} | |
This file contains 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
import Html (..) | |
import Html.Attributes (..) | |
import Html.Events (..) | |
import Signal ((<~), Signal) | |
import Signal | |
import Markdown | |
-- MODEL -- | |
type alias Model = String | |
emptyModel : Model | |
emptyModel = "" | |
-- UPDATE -- | |
type Action | |
= NoOp | |
| UpdateField String | |
update : Action -> Model -> Model | |
update action model = | |
case action of | |
NoOp -> model | |
UpdateField str -> str | |
-- VIEW-- | |
view : Model -> Html | |
view model = | |
div | |
[] | |
[ textarea | |
[ placeholder "Type Markdown Here" | |
, value model | |
, autofocus True | |
, cols 80 | |
, rows 20 | |
, on "input" targetValue (Signal.send updates << UpdateField) | |
] | |
[], | |
p [] [ Markdown.toHtml model ] | |
] | |
-- INPUTS -- | |
main : Signal Html | |
main = view <~ model | |
model : Signal Model | |
model = Signal.foldp update emptyModel (Signal.subscribe updates) | |
updates : Signal.Channel Action | |
updates = Signal.channel NoOp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment