NoRedInk/noredink-ui/23.3.0

NOTE: the latest version is 35.9.3

Nri.Ui.Highlightable.V3

A Highlightable represents a span of text, typically a word, and its state.

Highlightable is the unit by which text-wrapping happens. Depending on how the Highlighter is initialized, it's very possible for a Highlightable to consist of just a single whitespace.

Changes from V2

  • move the uIState out of the Highlightable
  • make the attribute modeling more flexible
  • replace init with initStatic and initInteractive, and remove attributes from the UI since they're seldom used
  • remove UIState: it only makes sense in the context of an interactive highlighter
  • joinAdjacentInteractiveHighlights now takes a sorter
  • initFragments no longer takes a list of markers

Types

type alias Highlightable marker =
{ text : String
, customAttributes : List (Attribute Never)
, marked : List (MarkerModel marker)
, index : Int
, type_ : Type
}

A Highlightable comes in two flavors:

  • Highlightable | Interactive piece of text.

  • Static | Non-interactive piece of text.

    Data for a Highlightable:

  • text: String to display.

  • customAttributes: User-supplied, non-interactive HTML attributes.

  • marked: Current highlights, if any.

  • index: Unique highlightable index.

type Type
= Interactive
| Static

Initializers

initStatic : List (MarkerModel marker) -> Int -> String -> Highlightable marker
initInteractive : List (MarkerModel marker) -> Int -> String -> Highlightable marker
initFragments : String -> List (Highlightable marker)

Initialize highlightables from a string.

Note that we're transforming all whitespace to spaces, so newlines are not preserved as me move to and from fragments. Spaces will be treated as static elements. Words will be interactive.

fromMarkdown : String -> List (Highlightable ())

How do we know which elements should be marked, if all we have is a markdown string?

We do some funky parsing to interpret empty anchor tags and tagged spans as highlighted!

fromMarkdown "for example, [this phrase]() will show as highlighted"

will result in a list of highlightables where "this phrase" is marked with the default marker.

UIState and marker

set :
Maybe (MarkerModel marker)
-> Highlightable marker
-> Highlightable marker
joinAdjacentInteractiveHighlights : Sorter m -> List (Highlightable m) -> List (Highlightable m)

Getters

asFragmentTuples : List (Highlightable marker) -> List ( List marker, String )

Get a list of fragment texts and whether or not they are marked. Useful for encoding answers.

usedMarkers : Sorter marker -> List (Highlightable marker) -> Set marker

Get unique markers that have been used. Note: ignores marks on whitespace.

text : List (Highlightable marker) -> String

Fetch the text from a series of highlightables.

byId : Int -> List (Highlightable kind) -> Maybe (Highlightable kind)

Get the highlightable matching the passed-in ID, if any.

Modules