Skip to content

Instantly share code, notes, and snippets.

@capicue
Last active August 29, 2015 14:17
Show Gist options
  • Save capicue/9565df3f0850a24a6ad3 to your computer and use it in GitHub Desktop.
Save capicue/9565df3f0850a24a6ad3 to your computer and use it in GitHub Desktop.
{
"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