Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Created April 22, 2017 05:52
Show Gist options
  • Select an option

  • Save glinesbdev/9f6dfa995ac5c95a26554209bdc4b44e to your computer and use it in GitHub Desktop.

Select an option

Save glinesbdev/9f6dfa995ac5c95a26554209bdc4b44e to your computer and use it in GitHub Desktop.
Text to Html
module Main exposing (..)
import Html exposing (Html, text, img, div)
import Html.Attributes exposing (src)
sampleText : String
sampleText =
"Once during your turn (before you attack), you may turn all basic Energy attached to all of your Pokémon into Fire Energy for the rest of the turn. This power can't be used if Charizard is affected by a Special Condition."
splitText : String -> List String
splitText string =
String.words string
replaceText : List String -> Html a
replaceText words =
let
url =
"https://s3-us-west-2.amazonaws.com/pokecard/assets/icons/elements/Fire-icon.png"
in
List.map (\word ->
case word of
"Fire" ->
img [ src url ] []
_ as val ->
" " ++ val ++ " "
|> text
) words
|> div []
main : Html a
main =
sampleText |> splitText |> replaceText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment