From 3601e01fc82931e5cfcf610a7f39b46ffe691766 Mon Sep 17 00:00:00 2001 From: Kelsey Mills Date: Wed, 6 Nov 2024 11:58:38 +0000 Subject: [PATCH] Implement interface for generic section --- block_rich_text.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block_rich_text.go b/block_rich_text.go index 9b25bbf1..26b3bd60 100644 --- a/block_rich_text.go +++ b/block_rich_text.go @@ -81,6 +81,11 @@ type RichTextElement interface { RichTextElementType() RichTextElementType } +type RichTextElementGenericSection interface { + RichTextElement + SectionElements() []RichTextSectionElement +} + const ( RTEList RichTextElementType = "rich_text_list" RTEPreformatted RichTextElementType = "rich_text_preformatted" @@ -188,6 +193,10 @@ func (s RichTextSection) RichTextElementType() RichTextElementType { return s.Type } +func (s RichTextSection) SectionElements() []RichTextSectionElement { + return s.Elements +} + func (e *RichTextSection) UnmarshalJSON(b []byte) error { var raw struct { RawElements []json.RawMessage `json:"elements"` @@ -490,6 +499,10 @@ func (s *RichTextQuote) RichTextElementType() RichTextElementType { return s.Type } +func (s RichTextQuote) SectionElements() []RichTextSectionElement { + return s.Elements +} + func (s *RichTextQuote) UnmarshalJSON(b []byte) error { // reusing the RichTextSection struct, as it's the same as RichTextQuote. var rts RichTextSection @@ -519,6 +532,10 @@ func (s *RichTextPreformatted) RichTextElementType() RichTextElementType { return s.Type } +func (s RichTextPreformatted) SectionElements() []RichTextSectionElement { + return s.Elements +} + func (s *RichTextPreformatted) UnmarshalJSON(b []byte) error { var rts RichTextSection if err := json.Unmarshal(b, &rts); err != nil {