Documentation ¶
Overview ¶
Package annotate provides an annotation framework for HTML content.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.