This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
A type for representing formatted text
version 2.3.4
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.3.4
Committed At 2018-06-12 07:22:34 UTC
pablohirafuji/elm-markdown 2.0.4 <= v < 3.0.0 2.0.5
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1
elm-community/elm-test 4.0.0 <= v < 5.0.0 4.2.0
NoRedInk/elm-compare 1.0.0 <= v < 2.0.0 1.1.0

README

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.

  • Use formattedText to combine a string with some formatting ranges. Ranges are allowed to overlap.
  • Use fromString to turn a string into an unformatted FormattedText.
  • Use unchunk to create a FormattedText from a list of chunks, pieces of text with homogeneous formatting.

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