Expand description
§text-document
A rich text document model for Rust.
Provides a TextDocument as the main entry point and TextCursor for
cursor-based editing, inspired by Qt’s QTextDocument/QTextCursor API.
use text_document::{TextDocument, MoveMode, MoveOperation};
let doc = TextDocument::new();
doc.set_plain_text("Hello world").unwrap();
let cursor = doc.cursor();
cursor.move_position(MoveOperation::EndOfWord, MoveMode::KeepAnchor, 1);
cursor.insert_text("Goodbye").unwrap(); // replaces "Hello"
// Multiple cursors on the same document
let c1 = doc.cursor();
let c2 = doc.cursor_at(5);
c1.insert_text("A").unwrap();
// c2's position is automatically adjusted
doc.undo().unwrap();Modules§
- matching
- The matcher, as a pure function over
&str— no document, no store, no threads.
Structs§
- Batch
Document - A headless document: no thread, no view, no cursor. See the module docs.
- Block
Format - Block (paragraph) formatting. All fields are optional.
- Block
Info - Info about a block at a given position.
- Block
Snapshot - All layout-relevant data for one block, captured atomically.
- Cell
Format - Cell-level formatting.
- Cell
Range - A rectangular range of cells within a single table (inclusive bounds).
- Cell
Snapshot - Snapshot of one table cell including its block content.
- Color
- An RGBA color value. Each component is 0–255.
- Djot
Export Options - Selects which optional block attributes the djot exporter emits as
{key=value}block attributes. A disabled attribute is omitted from the output even when the model carries a value for it. - Djot
Import Options - Selects which optional block attributes the djot importer applies to the document model. An attribute present in the source but disabled here is parsed and discarded, exactly like an unrepresentable construct.
- Document
Fragment - A piece of rich text that can be inserted into a
TextDocument. - Document
Stats - Document-level statistics. O(1) cached.
- Docx
Export Options - Page geometry + base typography overrides for a DOCX export. Every field is optional; the
Defaultis “no overrides” — exactly what plainto_docxproduces. - Docx
Export Result - Result of a DOCX export (
to_docx). - Epub
Export Options - Book-level metadata for an EPUB export. Every field is required by the container format in
some form, so unlike
super::docx_options::DocxExportOptionsthere is no “no overrides” default that matches an unconfigured EPUB —Defaultinstead picks the most reasonable placeholders. - Epub
Export Result - Result of an EPUB export (
to_epub). - Find
Match - A single search match.
- Find
Options - Options for find / find_all / replace operations.
- Flow
Snapshot - Consistent snapshot of the entire document flow, captured in a single lock acquisition.
- Frame
Format - Frame formatting. All fields are optional.
- Frame
Ref - Reference to the frame that immediately encloses the cursor’s block.
depthis the nesting level (1 for a direct child of the root).is_blockquoteis true ifffmt_is_blockquoteisSome(true). - Frame
Snapshot - Snapshot of a sub-frame and its contents.
- Highlight
Context - Context passed to
SyntaxHighlighter::highlight_block. - Highlight
Format - Formatting applied by a syntax highlighter to a text range.
- Highlight
Mask - Which highlight sessions a particular view renders.
- Highlight
Span - A single highlight span within a block.
- Html
Import Result - Result of an HTML import (
set_html). - List
Format - List formatting. All fields are optional:
Nonemeans “not set — don’t change this property.” - List
Info - List membership and marker information for a block.
- Markdown
Import Result - Result of a Markdown import (
set_markdown). - Operation
- A handle to a running long operation (Markdown/HTML import, DOCX export).
- Paint
Highlight Span - A resolved paint-only highlight span for one character range of a block.
- PdfExport
Options - Page geometry + typography + embedded font bytes for a PDF export.
- PdfExport
Result - Result of a PDF export (
to_pdf). - Range
Highlight - One highlight range carried by a range session, in absolute document char offsets —
the same coordinate space
crate::FindMatchand replace report in. - Replace
Options - Options for a replace: how to find the text, and what the replacement wears where it overwrites formatted prose.
- Replace
Range - One range to replace, with its own replacement text.
- Session
Id - Identifies one registered highlight session (see
crate::TextDocument::add_syntax_session/crate::TextDocument::add_range_session). - Subscription
- Handle to a document event subscription.
- Table
Cell Context - Snapshot-friendly reference to a table cell (plain IDs, no live handles).
- Table
Cell Ref - Reference to a table cell that contains a block.
- Table
Format - Table-level formatting.
- Table
Snapshot - Consistent snapshot of a table’s structure and all cell content.
- Text
Block - A lightweight, read-only handle to a single block (paragraph).
- Text
Cursor - A cursor into a
TextDocument. - Text
Document - A rich text document.
- Text
Format - Character/text formatting. All fields are optional:
Nonemeans “not set — inherit from the block’s default or the document’s default.” - Text
Frame - A read-only handle to a frame in the document.
- Text
List - A read-only handle to a list in the document.
- Text
Table - A read-only handle to a table in the document.
- Text
Table Cell - A read-only handle to a single cell within a table.
- Word
Char Counts - The three counts a caller might display. All three are always computed — “characters with spaces” vs “without” is a display choice, not a separate counting mode.
Enums§
- Alignment
- Cell
Vertical Alignment - Vertical alignment within a table cell.
- Char
Vertical Alignment - Count
Method - How words are delimited. Characters are always counted the same way (Unicode scalar
values), independent of this choice — see
WordCharCounts. - Document
Error - Errors returned by the public
text-documentAPI. - Document
Event - Events emitted by a
TextDocument. - Flow
Element - An element in the document’s visual flow.
- Flow
Element Snapshot - Snapshot of one flow element.
- Format
Change Kind - What kind of formatting changed.
- Fragment
Content - A contiguous run of content with uniform formatting within a block.
- Frame
Position - Inline
Content - Content type for an inline segment: text, image, or empty.
- List
Style - Marker
Type - Move
Mode - Controls whether a movement collapses or extends the selection.
- Move
Operation - Semantic cursor movement operations.
- Replace
Format Policy - What the replacement text wears when it overwrites formatted text.
- Resource
Type - Selection
Kind - Describes what kind of selection the cursor currently has.
- Selection
Type - Quick-select a region around the cursor.
- Text
Direction - Underline
Style - Wrap
Mode
Constants§
- TABLE_
ANCHOR - The
U+FFFC OBJECT REPLACEMENT CHARACTERthat stands for a table in the document’s text.
Traits§
- Syntax
Highlighter - A user-implemented syntax highlighter that applies visual-only formatting.
Functions§
- count
- Count words and characters in already-extracted plain text.
- count_
djot - Extract prose from Djot source, then count. The two-step (strip then count) is kept
deliberately simple:
djot_to_plain_textcarries a pinned contract (table-anchor sentinel, single-\nblock joins) and fusing the parse-and-count into one AST walk is the easiest way to accidentally create a third, silently-diverging “what is the text”. - djot_
to_ plain_ text - The prose of a Djot document, with no entities, no store, and no threads.
Type Aliases§
- Result
- Result alias used throughout the public API.