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 ¶
- func FixTemplateDirectives(s *goquery.Selection)
- func NewHandler(opts ...Option) filesys.HandlerFunc
- func StripComments(s *goquery.Selection)
- type Node
- func (n *Node) Derive(selection *goquery.Selection) *Node
- func (n *Node) Descend(names ...string) drill.Node
- func (n *Node) Document() *goquery.Document
- func (n *Node) Fragment() string
- func (n *Node) FragmentReader() (r io.ReadCloser, err error)
- func (n *Node) Len() int
- func (n *Node) OrderedChild(i int) drill.Node
- func (n *Node) OrderedChildren() []drill.Node
- func (n *Node) Query(queries ...interface{}) drill.Node
- func (n *Node) Selection() *goquery.Selection
- func (n *Node) UnorderedChild(name string) drill.Node
- func (n *Node) UnorderedChildren() map[string]drill.Node
- func (n *Node) WithRenderer(r Renderer) *Node
- type Option
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixTemplateDirectives ¶
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 ¶
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 (*Node) Descend ¶
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) Fragment ¶
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) OrderedChild ¶
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 ¶
OrderedChildren returns a list of Nodes that wrap each ordered child Section.
func (*Node) Query ¶
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) UnorderedChild ¶
UnorderedChild returns a Node that wraps the unordered child section element whose data-name attribute is equal to name.
func (*Node) UnorderedChildren ¶
UnorderedChildren returns a map of names to Nodes that wrap each unordered child section element.
func (*Node) WithRenderer ¶
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 ¶
WithRenderer configures a handler to return nodes that use the given renderer.