Skip to content

Instantly share code, notes, and snippets.

@capicue
Last active Aug 29, 2015
Embed
What would you like to do?
{
"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"
}
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