RichText — Aspose.Note FOSS for Python API Reference

Class: RichText

Package: aspose.note Import: from aspose.note import RichText Inherits: CompositeNode

RichText represents a block of styled text within an OutlineElement, TableCell, or Title. It exposes the full plain-text content via .Text and individual formatting segments via .Runs.


Properties

PropertyTypeAccessDescription
TextstrReadFull plain-text string (all runs concatenated)
Runslist[TextRun]ReadOrdered list of individually formatted segments
FontSizefloat | NoneReadParagraph-level font size in points
Tagslist[NoteTag]ReadOneNote tags attached to this text block

Inherited from CompositeNode / Node

PropertyDescription
ParentNodeContaining node (OutlineElement, TableCell, Title)
DocumentRoot Document

Methods

Append(text, style=None)

rt.Append(text: str, style: TextStyle | None = None) -> RichText

Appends a new text run with optional style. Returns self for chaining. Operates in-memory; changes cannot be saved back to .one.

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
first_rt = doc.GetChildNodes(RichText)[0]
first_rt.Append(" [reviewed]")

Replace(old_value, new_value)

rt.Replace(old_value: str, new_value: str) -> None

Substitutes all occurrences of old_value with new_value across all runs. Operates in-memory.

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    rt.Replace("TODO", "DONE")

Accept(visitor)

rt.Accept(visitor: DocumentVisitor) -> None

Dispatches VisitRichTextStart(rt) and VisitRichTextEnd(rt) on the visitor.


TextRun

Each element of RichText.Runs is a TextRun:

PropertyTypeDescription
TextstrSegment text
StyleTextStyleFormatting properties for this segment
Startint | NoneCharacter offset of segment start within RichText.Text
Endint | NoneCharacter offset of segment end

TextStyle

TextRun.Style is a TextStyle with the following properties:

PropertyTypeDescription
BoldboolBold
ItalicboolItalic
UnderlineboolUnderline
StrikethroughboolStrikethrough
SuperscriptboolSuperscript
SubscriptboolSubscript
FontNamestr | NoneFont family name
FontSizefloat | NoneFont size in points
FontColorint | NoneFont color as ARGB integer
HighlightColorint | NoneHighlight background color as ARGB integer
LanguageIdint | NoneLanguage identifier (LCID)
IsHyperlinkboolWhether this run is a hyperlink
HyperlinkAddressstr | NoneHyperlink URL (when IsHyperlink is True)

Usage Examples

Get all plain text

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    if rt.Text:
        print(rt.Text)

Inspect all runs with formatting

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 = [a for a, v in [
            ("bold", s.Bold), ("italic", s.Italic),
            ("underline", s.Underline), ("strike", s.Strikethrough),
        ] if v]
        label = ", ".join(attrs) or "plain"
        print(f"  [{label}] {run.Text!r}")

Extract hyperlinks

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}")

Find all bold text

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
bold_segments = [
    run.Text for rt in doc.GetChildNodes(RichText)
    for run in rt.Runs
    if run.Style.Bold and run.Text.strip()
]
print(bold_segments)

Read tags

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        print(f"Tag: {tag.label!r}  on text: {rt.Text.strip()!r}")

None-Safety

Text is always a str (never None). Runs is always a list (may be empty). FontSize, FontColor, HighlightColor, LanguageId, HyperlinkAddress can be None.


See Also