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 .TextRuns.
Properties
| Property | Type | Access | Description |
|---|---|---|---|
Text | str | Read | Full plain-text string (all runs concatenated) |
TextRuns | list[TextRun] | Read | Ordered list of individually formatted segments |
Tags | list[NoteTag] | Read | OneNote tags attached to this text block |
Inherited from CompositeNode / Node
| Property | Description |
|---|---|
ParentNode | Containing node (OutlineElement, TableCell, Title) |
Document | Root Document |
Methods
Append(text, style=None)
rt.Append(text: str, style: TextStyle | None = None) -> RichText # appends to TextRunsAppends 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) -> NoneSubstitutes 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) -> NoneDispatches VisitRichTextStart(rt) and VisitRichTextEnd(rt) on the visitor.
TextRun
Each element of RichText.TextRuns is a TextRun:
| Property | Type | Description |
|---|---|---|
Text | str | Segment text |
Style | TextStyle | Formatting properties for this segment |
TextStyle
TextRun.Style is a TextStyle with the following properties:
| Property | Type | Description |
|---|---|---|
IsBold | bool | Bold |
IsItalic | bool | Italic |
IsUnderline | bool | Underline |
IsStrikethrough | bool | Strikethrough |
IsSuperscript | bool | Superscript |
IsSubscript | bool | Subscript |
FontName | str | None | Font family name |
FontSize | float | None | Font size in points |
FontColor | int | None | Font color as ARGB integer |
Highlight | int | None | Highlight background color as ARGB integer |
Language | int | None | Language identifier (LCID) |
IsHyperlink | bool | Whether this run is a hyperlink |
HyperlinkAddress | str | None | Hyperlink 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.TextRuns:
s = run.Style
attrs = [a for a, v in [
("bold", s.IsBold), ("italic", s.IsItalic),
("underline", s.IsUnderline), ("strike", s.IsStrikethrough),
] 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.TextRuns:
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.TextRuns
if run.Style.IsBold 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). TextRuns is always a list (may be empty). Tags is always a list (may be empty). Per-run properties such as FontSize, FontColor, Highlight, Language, and HyperlinkAddress belong to TextStyle on each TextRun and may be None.
See Also
- Page: ancestor of RichText
- TextRun: individual formatted segment
- TextStyle: formatting properties
- NoteTag: tags on text
- Text Extraction Developer Guide
- How-to: Extract Text from OneNote (KB)
- Blog: Extract Text from OneNote in Python