annotate

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package annotate provides an annotation framework for HTML content.

Index

Constants

This section is empty.

Variables

View Source
var ErrAnotate *annotationError

ErrAnotate represents an error during the annotation creation.

Functions

func AddAnnotation

func AddAnnotation(
	root *html.Node, tagName string,
	startSelector string, startOffset int,
	endSelector string, endOffset int,
	options ...WrapCallback,
) error

AddAnnotation is the main function that will add an annotation to a given root node. It lets one set an annotation tag name and performs the overlap validation. The root node is modified in place.

Types

type Annotation

type Annotation struct {
	// contains filtered or unexported fields
}

Annotation holds raw information about an annotation. It contains only selectors and offset used to find the relevant text nodes when looking up for a range.

func NewAnnotation

func NewAnnotation(root *html.Node, startSelector string, startOffset int, endSelector string, endOffset int) *Annotation

NewAnnotation creates a new Annotation instance.

func (*Annotation) ToRange

func (a *Annotation) ToRange(validators ...func(*AnnotationRange) error) (r *AnnotationRange, err error)

ToRange returns AnnotationRange instance from the current Annotation. This method finds the text nodes, common ancestor and validates that the range can be wraped later.

type AnnotationRange

type AnnotationRange struct {
	// contains filtered or unexported fields
}

AnnotationRange holds the necessary DOM information to find and wrap an full annotation on a node.

func (*AnnotationRange) Wrap

func (r *AnnotationRange) Wrap(options ...WrapCallback)

Wrap insert annotation elements around the range text nodes.

type WrapCallback

type WrapCallback func(node *html.Node, index int)

WrapCallback is a function called on each annotation wrapping node. As an annotation can be covered by several wrapping nodes, an index gives the current wrapping position.

Jump to

Keyboard shortcuts

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