jomei / notionapi

A Notion API SDK, written in Golang

Home Page:https://pkg.go.dev/github.com/jomei/notionapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Util functions for RichText properties

chapterjason opened this issue · comments

I often just want to get the plain text from a property like the TitleProperty to print it in log or somewhere else.

What about adding some util functions which concats the []RichText and returns it as string.

Something like:

func (p TitleProperty) GetPlainText() string {
	builder := strings.Builder{}

	for _, title := range p.Title {
		builder.WriteString(title.PlainText)
		builder.WriteString(" ")
	}

	return strings.TrimSpace(builder.String())
}

We could also add something like GetMarkdown or getHTML, but with some limitations like the color annotation in markdown wouldn't work.

Would affect the following properties:

  • TitleProperty
  • RichTextProperty
  • TextProperty

WDYT?

Hi, @chapterjason !
To be honest, I'm not sure that suggested functionality should be implemented on the package side. The purpose of this library is providing usage of Notion API for Golang. Any utils can be easily added on client's side.