TextRun — Aspose.Note FOSS for Python API Reference

Class: TextRun

Package: aspose.note Import: from aspose.note import TextRun

TextRun represents a single contiguous segment of text that shares uniform formatting within a RichText block. A RichText.TextRuns 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

PropertyTypeAccessDescription
TextstrRead/WriteThe text content of this segment. Defaults to "".
StyleTextStyleRead/WriteFormatting properties for this segment. See TextStyle.

Relationship to RichText

Every RichText node owns a list of TextRun objects via RichText.TextRuns. Concatenating run.Text for all runs yields the full RichText.Text:

RichText.Text == "".join(run.Text for run in RichText.TextRuns)

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.TextRuns:
        s = run.Style
        attrs = []
        if s.IsBold:        attrs.append("bold")
        if s.IsItalic:      attrs.append("italic")
        if s.IsUnderline:   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.TextRuns:
        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 ""). Style is always present.


See Also