Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noredink/elm-formatted-text
A type for representing formatted text
https://github.com/noredink/elm-formatted-text
Last synced: about 2 months ago
JSON representation
A type for representing formatted text
- Host: GitHub
- URL: https://github.com/noredink/elm-formatted-text
- Owner: NoRedInk
- License: bsd-3-clause
- Created: 2017-07-09T11:45:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-17T09:59:25.000Z (about 2 years ago)
- Last Synced: 2024-05-08T23:24:59.924Z (8 months ago)
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/NoRedInk/elm-formatted-text/latest
- Size: 132 KB
- Stars: 5
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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`.```elm
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 [] childrenItalic ->
Html.i [] children
```