htmldrill

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

The htmldrill package implements a drill/filesys.Handler for the HTML format. Drill nodes are delimited by "section" elements. Unordered nodes are implemented as section elements with the "data-name" attribute.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixTemplateDirectives

func FixTemplateDirectives(s *goquery.Selection)

FixTemplateDirectives splits TextNodes by template directives. Directives are inserted as RawNodes. Directives are assumed not to span across multiple TextNodes.

func NewHandler

func NewHandler(opts ...Option) filesys.HandlerFunc

NewHandler returns a filesys.HandlerFunc that parses a file as an HTML document.

func StripComments

func StripComments(s *goquery.Selection)

StripComments removes comment nodes from the selection.

Types

type Node

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

Node implements drill.Node. A Node represents either a single section element, or the body of a document.

func NewNode

func NewNode(doc *goquery.Document, renderer Renderer) *Node

NewNode returns a Node that wraps the given goquery.Document and optional renderer.

func (*Node) Derive

func (n *Node) Derive(selection *goquery.Selection) *Node

Derive returns a Node that wraps selection instead of the selection from n.

func (*Node) Descend

func (n *Node) Descend(names ...string) drill.Node

Descend recursively descends into the unordered child section elements matching each given name. Returns nil if a child could not be found at any point.

func (*Node) Document

func (n *Node) Document() *goquery.Document

Document returns the root goquery.Document.

func (*Node) Fragment

func (n *Node) Fragment() string

Fragment renders the wrapped node as a string using the node's renderer, or goquery.Render if the node has no renderer. Returns an empty string if an error occurs.

func (*Node) FragmentReader

func (n *Node) FragmentReader() (r io.ReadCloser, err error)

FragmentReader returns a ReadCloser that renders the wrapped node according the node's renderer, or goquery.Render if the node has no renderer. Errors are passed to the reader.

func (*Node) Len

func (n *Node) Len() int

Len returns the number of child section elements.

func (*Node) OrderedChild

func (n *Node) OrderedChild(i int) drill.Node

OrderedChild returns a Node that wraps the ordered child section element at index i. Returns nil if the index is out of bounds.

func (*Node) OrderedChildren

func (n *Node) OrderedChildren() []drill.Node

OrderedChildren returns a list of Nodes that wrap each ordered child Section.

func (*Node) Query

func (n *Node) Query(queries ...interface{}) drill.Node

Query recursively descends into the child nodes that match the given queries. A query is either a string or an int. If an int, then the next node is acquired using the OrderedChild method of the current node. If a string, then the next node is acquired using the UnorderedChild method of the current node. Returns nil if a child could not be found at any point.

func (*Node) Selection

func (n *Node) Selection() *goquery.Selection

Selection returns the wrapped goquery.Selection.

func (*Node) UnorderedChild

func (n *Node) UnorderedChild(name string) drill.Node

UnorderedChild returns a Node that wraps the unordered child section element whose data-name attribute is equal to name.

func (*Node) UnorderedChildren

func (n *Node) UnorderedChildren() map[string]drill.Node

UnorderedChildren returns a map of names to Nodes that wrap each unordered child section element.

func (*Node) WithRenderer

func (n *Node) WithRenderer(r Renderer) *Node

WithRenderer returns a copy of the node that uses the given renderer. r may be nil.

type Option

type Option func(*config)

Option configures the package's filesys handler.

func WithParseOptions

func WithParseOptions(opts ...html.ParseOption) Option

WithParseOptions configures how a handler parses HTML.

func WithRenderer

func WithRenderer(renderer Renderer) Option

WithRenderer configures a handler to return nodes that use the given renderer.

type Renderer

type Renderer func(w io.Writer, s *goquery.Selection) error

Renderer renders a selection, writing the result to w. s will contain either a body or section element.

Jump to

Keyboard shortcuts

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