RichText

RichText — Aspose.Note FOSS for Python API Reference

คลาส: RichText

Properties: aspose.note Properties: from aspose.note import RichText Properties: CompositeNode

RichText เป็นบล็อกของข้อความที่มีการจัดรูปแบบภายใน OutlineElement, TableCell, หรือ Title. มันเปิดเผยเนื้อหาข้อความธรรมดาเต็มรูปแบบผ่าน .Text และส่วนของการจัดรูปแบบแยกส่วนผ่าน .Runs.


Properties

PropertiesPropertiesPropertiesProperties
TextstrPropertiesสตริงข้อความธรรมดาเต็มรูปแบบ (ทุกรันต่อเนื่องกัน)
Runslist[TextRun]Propertiesรายการลำดับของส่วนที่จัดรูปแบบแยกกัน
FontSize`floatNone`Properties
Tagslist[NoteTag]Propertiesแท็ก OneNote ที่แนบกับบล็อกข้อความนี้

สืบทอดจาก CompositeNode / Node

PropertiesProperties
ParentNodeโหนดที่บรรจุ (OutlineElement, TableCell, Title)
Documentเอกสารราก

Properties

Properties

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

เพิ่มรันข้อความใหม่พร้อมสไตล์ที่เป็นตัวเลือก คืนค่า self เพื่อการเชื่อมต่อ ทำงานในหน่วยความจำ; การเปลี่ยนแปลงไม่สามารถบันทึกกลับไปยัง .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

แทนที่ทุกการปรากฏของ old_value ด้วย new_value ทั่วทุกรัน ทำงานในหน่วยความจำ.

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

Properties VisitRichTextStart(rt) และ VisitRichTextEnd(rt) บนผู้เยี่ยมชม.


TextRun

แต่ละองค์ประกอบของ RichText.Runs เป็น TextRun:

PropertiesPropertiesProperties
Textstrข้อความส่วน
StyleTextStyleคุณสมบัติการจัดรูปแบบสำหรับส่วนนี้
Start`intNone`
End`intNone`

TextStyle

TextRun.Style เป็น TextStyle พร้อมคุณสมบัติดังต่อไปนี้:

PropertiesPropertiesProperties
BoldboolProperties
ItalicboolProperties
UnderlineboolProperties
StrikethroughboolProperties
SuperscriptboolProperties
SubscriptboolProperties
FontName`strNone`
FontSize`floatNone`
FontColor`intNone`
Highlight`intNone`
Language`intNone`
IsHyperlinkboolว่าการรันนี้เป็นไฮเปอร์ลิงก์หรือไม่
HyperlinkAddress`strNone`

ตัวอย่างการใช้งาน

ดึงข้อความธรรมดาทั้งหมด

from aspose.note import Document, RichText

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

ตรวจสอบรันทั้งหมดพร้อมการจัดรูปแบบ

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

สกัดลิงก์

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

ค้นหาข้อความหนาทั้งหมด

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)

อ่านแท็ก

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

Text เป็นเสมอ a str (ไม่เคย None). Runs เป็นรายการเสมอ (อาจว่างเปล่า). FontSize, FontColor, Highlight, Language, HyperlinkAddress สามารถเป็น None.


ดูเพิ่มเติม

 ภาษาไทย