Skip to main content

Module text

Module text 

Source
Expand description

Text helpers shared by the engines: markup stripping, previews, whole-word matching, tag balance and serialized sizes.

Statics§

WHITESPACE_TO_COLLAPSE 🔒
Whitespace that isn’t a single space; collapsing only these leaves most text borrowed.

Functions§

collapse_whitespace 🔒
is_inside_character_reference
Whether byte offset at falls after the & of a character reference such as & and at or before its ;.
is_inside_tag
Whether byte offset at of html falls inside a tag (<a href="…">).
is_word_char 🔒
Letters, digits and _, non-ASCII ones included. main-frontend’s glossary highlighting (textParsing.tsx) uses the same set; change both together.
open_tags_at
Inline elements still open at byte offset at, outermost first.
plain_text
The visible text of a rich-text string: tags removed, common entities decoded, whitespace collapsed to single spaces.
preview
Cuts text to at most max_chars characters at a word boundary, adding an ellipsis when cut.
serialized_len
The size of value as JSON, in bytes, without building the JSON.
whole_word_matches
Byte ranges of the occurrences of needle in text that don’t start or end inside a word. An end of needle that isn’t a word character (as in “C++”) needs no word boundary.