NoRedInk/elm-formatted-text-19 - version: 1.0.0

for more information visit the package's GitHub page

Package contains the following modules:

FormattedText

The FormattedText type represents some text with markup applied to it. The goal of this library is to make working with such text as easy as working with strings.

Creating FormattedText

You can create a FormattedText in a number of ways.

Manipulating FormattedText

Anything you can do with Strings you can do with FormattedText too, because this lib comes with equivalents of all functions from the core String and Regex modules.

Rendering FormattedText

The easiest way to render FormattedText into Html is using the trees function, which builds a markup tree from your FormattedText.

import FormattedText exposing (..)
import Html exposing (Html)

type Markup = Bold | Italic

view : FormattedText Markup -> Html msg
view formattedText =
    Html.p [] (trees Html.text viewMarkup)

viewMarkup : Markup -> List (Html msg) -> Html msg
viewMarkup markup children =
    case markup of
        Bold ->
            Html.strong [] children

        Italic ->
            Html.i [] children