TextRun — Aspose.Note FOSS for Python API Reference
Class: TextRun
Package: aspose.note
Import: from aspose.note import TextRun
Inherits: Node
TextRun represents a single contiguous segment of text that shares uniform formatting within a RichText block. A RichText.Runs list contains one or more TextRun objects; each has its own Style (TextStyle). This is the finest-grained unit of formatted text in the document model.
Properties
| Property | Type | Access | Description |
|---|---|---|---|
Text | str | Read/Write | The text content of this segment. Defaults to "". |
Style | TextStyle | Read/Write | Formatting properties for this segment. See TextStyle. |
Start | int | None | Read | Character offset of this segment’s start within RichText.Text. |
End | int | None | Read | Character offset of this segment’s end within RichText.Text. |
Inherited from Node
| Property | Type | Description |
|---|---|---|
ParentNode | Node | None | The containing RichText node |
Document | Document | None | Root document |
Relationship to RichText
Every RichText node owns a list of TextRun objects via RichText.Runs. Concatenating run.Text for all runs yields the full RichText.Text:
RichText.Text == "".join(run.Text for run in RichText.Runs)Each run carries an independent Style, so a single paragraph can contain mixed bold, italic, hyperlink, or differently-coloured segments.
Usage Example
Inspect all runs in a document
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.Runs:
s = run.Style
attrs = []
if s.Bold: attrs.append("bold")
if s.Italic: attrs.append("italic")
if s.Underline: attrs.append("underline")
if s.IsHyperlink: attrs.append(f"link={s.HyperlinkAddress!r}")
label = ", ".join(attrs) or "plain"
print(f"[{label}] {run.Text!r}")Find all hyperlink runs
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.Runs:
if run.Style.IsHyperlink and run.Style.HyperlinkAddress:
print(f"{run.Text!r} -> {run.Style.HyperlinkAddress}")None-Safety
Text is always a str (never None; defaults to ""). Start and End may be None for runs created programmatically before they are attached to a RichText. Style is always present.
See Also
- RichText: parent node that owns
Runs - TextStyle: formatting properties for a
TextRun - Node: base class
- Developer Guide