renderer

package
v0.0.0-...-bbf0d79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const MaxBlocksPerUpdate = 100

MaxBlocksPerUpdate is the maximum number of blocks that can be added in a single request.

See https://developers.notion.com/reference/patch-block-children

View Source
const MaxNestedBlockLevelsPerUpdate = 2

MaxNestedBlockLevelsPerUpdate is the maximum number of nesting levels that can be added in a single request.

See https://developers.notion.com/reference/patch-block-children

View Source
const MaxRichTextContentLength = 2000

MaxRichTextContentLength is the maximum length of a single rich text content object. See https://developers.notion.com/reference/request-limits#limits-for-property-values

Variables

View Source
var ErrDiscardLink = errors.New("discard link")

Functions

func IsDangerousURL

func IsDangerousURL(url []byte) bool

IsDangerousURL returns true if the given url seems a potentially dangerous url, otherwise false. Copied from https://sourcegraph.com/github.com/yuin/goldmark/-/blob/renderer/html/html.go?L997

func NewNodeRenderer

func NewNodeRenderer(ctx context.Context, block BlockUpdater, opts ...Option) goldmark.NodeRenderer

NewNodeRenderer returns a new NodeRenderer that ingests Markdown and applies converted Notion blocks to BlockUpdater.

Callers that just want to process Markdown should use markdown.NewProcessor instead.

Types

type BlockUpdater

type BlockUpdater interface {
	// AddChildren should add the given children to the desired parent block.
	//
	// The caller calls it while respecting MaxBlocksPerUpdate and
	// MaxRichTextContentLength - implementations can assume the set of children
	// being added is of a reasonable size and adhere's to Notion's API limits.
	AddChildren(ctx context.Context, children []notionapi.Block) error
}

BlockUpdater implements the desired handling for Notion blocks converted from Markdown. It should represent a single parent block, to which all children are added.

type DiscardLinkResolver

type DiscardLinkResolver struct{}

DiscardLinkResolver discards all links, using ErrDiscardLink to indicate all links should be rendered as plain text.

func (DiscardLinkResolver) ResolveLink(link string) (string, error)

type LinkResolver

type LinkResolver interface {
	// ResolveLink accepts a link and returns it as-is or modified as desired,
	// for example to resolve an appropriate absolute link to the relevant
	// resource (e.g. another Notion document or a blob view).
	//
	// If ErrDiscardLink is returned, the link is converted into a plain text
	// element.
	ResolveLink(link string) (string, error)
}

LinkResolver can be implemented to modify Markdown links.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option applies configuration of the renderer. It is intentionally unexported such that only this package can export Options.

func WithDebugHandler

func WithDebugHandler(fn func(line string)) Option

func WithLinkResolver

func WithLinkResolver(links LinkResolver) Option

WithLinkResolver configures a LinkResolver to use. Otherwise, a default no-op one is used that uses links as-is.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL