Skip to content

Commit

Permalink
Implement interface for generic section
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseymills committed Nov 6, 2024
1 parent 0c1f7fe commit 3601e01
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions block_rich_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3601e01

Please sign in to comment.