RichString

data class RichString(val text: String, val spans: List<RichSpan> = emptyList())

An immutable rich text representation that pairs plain text with type-safe attributes applied to specific character ranges.

All mutating operations return a new RichString instance, preserving the original unchanged.

Constructors

Link copied to clipboard
constructor(text: String, initialAttributes: AttributeContainer)

Creates a new RichString having the given initialAttributes applied to the entire text.

constructor(text: String, spans: List<RichSpan> = emptyList())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

A list of all RichSpans currently held by this RichString.

Link copied to clipboard

The plain text content.

Functions

Link copied to clipboard
fun edit(block: RichStringScope.() -> Unit): RichString

Executes the given block on a RichStringScope scoped to this RichString, and returns a completely new RichString carrying the modifications.

Link copied to clipboard
fun <T> RichString.export(exporter: RichTextExporter<T>): T

Exports this RichString using the specified exporter.

Link copied to clipboard

Extracts a list of semantic ListItems from the given RichString.

Link copied to clipboard
fun <T : Any> runs(key: AttributeKey<T>): <Error class: unknown class><RichRun<T>>

Retrieves all contiguous runs of the requested attribute key, merging internally split spans. Adjacent internal spans that possess the EXACT SAME attribute value for key will be combined into a single RichRun, ignoring differences in other attributes.

fun runs(predicate: (AttributeContainer) -> Boolean): <Error class: unknown class><RichRun<AttributeContainer>>

Retrieves all contiguous runs that satisfy the given predicate, merging internally split spans. Adjacent internal spans that satisfy the predicate and possess EXACTLY THE SAME attributes will be combined into a single RichRun.