Documentation

RichText
in package

This class embodies a RichText fragment.

Technically, a RichText fragment is not much more than an array of blocks, but there are many things to do with this fragment, including in the HTML serialization, but not only. It is arguably the most powerful and manipulable way any CMS stores structured text nowadays.

Table of Contents

asHtml()  : string
Builds a HTML version of the RichText fragment
asText()  : string
Builds a text version of the RichText fragment
asHtmlBlock()  : string
Transforms a block into HTML
insertSpans()  : string
Transforms a text block into HTML
serialize()  : string
Transforms an element into HTML

Methods

asHtml()

Builds a HTML version of the RichText fragment

public static asHtml(object $richText[, LinkResolver $linkResolver = null ][, lambda $htmlSerializer = null ]) : string
Parameters
$richText : object

the rich text object

$linkResolver : LinkResolver = null

the link resolver

$htmlSerializer : lambda = null

an optional function to generate custom HTML code

Return values
string

the HTML version of the RichText fragment

asText()

Builds a text version of the RichText fragment

public static asText(object $richText) : string
Parameters
$richText : object

the rich text object

Return values
string

the text version of the RichText fragment

asHtmlBlock()

Transforms a block into HTML

private static asHtmlBlock(object $block[, LinkResolver $linkResolver = null ][, lambda $htmlSerializer = null ]) : string
Parameters
$block : object

a given block

$linkResolver : LinkResolver = null

the link resolver

$htmlSerializer : lambda = null

the user's custom HTML serializer

Return values
string

the HTML representation of the block

insertSpans()

Transforms a text block into HTML

private static insertSpans(string $text, array<string|int, mixed> $spans[, LinkResolver $linkResolver = null ][, lambda $htmlSerializer = null ]) : string
Parameters
$text : string

the raw text of the block

$spans : array<string|int, mixed>

the spans of the block

$linkResolver : LinkResolver = null

the link resolver

$htmlSerializer : lambda = null

the user's custom HTML serializer

Return values
string

the HTML representation of the block

serialize()

Transforms an element into HTML

private static serialize(object $element, string $content, LinkResolver $linkResolver, lambda $htmlSerializer) : string
Parameters
$element : object

element to serialize

$content : string

inner HTML content of the element

$linkResolver : LinkResolver

the link resolver

$htmlSerializer : lambda

the user's custom HTML serializer

Return values
string

the HTML representation of the element

Search results