html

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 5 Imported by: 0

README

html

html defines a jquery-like html selection & iteration functions for HTML documents

Functions

html(markup) selection

parse an html document returing a selection at the root of the document

parameters:

name type description
markup string html text to build a document from

Types

selection

an HTML document for querying Methods

attr(name) string

gets the specified attribute's value for the first element in the Selection. To get the value for each element individually, use a looping construct such as each or map method

parameters:

name type description
name string attribute name to get the value of
children() selection

gets the child elements of each element in the Selection

children_filtered(selector) selection

gets the child elements of each element in the Selection, filtered by the specified selector

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
contents(selector) selection

gets the children of each element in the Selection, including text and comment nodes

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
find(selector) selection

gets the descendants of each element in the current set of matched elements, filtered by a selector

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
filter(selector) selection

filter reduces the set of matched elements to those that match the selector string

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
get(i) selection

retrieves the underlying node at the specified index. alias: eq

parameters:

name type description
i int numerical index of node to get
has(selector) selection

reduces the set of matched elements to those that have a descendant that matches the selector

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
parent(selector) selection

gets the parent of each element in the Selection

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
parents_until(selector) selection

gets the ancestors of each element in the Selection, up to but not including the element matched by the selector

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
siblings() selection

gets the siblings of each element in the Selection

text() string

gets the combined text contents of each element in the set of matched elements, including descendants

first(selector) selection

gets the first element of the selection

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
last() selection

gets the last element of the selection

parameters:

name type description
selector string a query selector string to filter the current selection, returning a new selection
len() int

returns the number of the nodes in the selection

eq(i) selection

gets the element at index i of the selection

parameters:

name type description
i int numerical index of node to get

Documentation

Overview

Package html defines a jquery-like html selection & iteration functions for HTML documents

outline: html
  html defines a jquery-like html selection & iteration functions for HTML documents

  functions:
    html(markup) selection
      parse an html document returing a selection at the root of the document
      params:
        markup string
          html text to build a document from

  types:
    selection
      an HTML document for querying
      methods:
        attr(name) string
          gets the specified attribute's value for the first element in the Selection.
          To get the value for each element individually, use a looping construct such as each or map method
          params:
            name string
              attribute name to get the value of
        children() selection
          gets the child elements of each element in the Selection
        children_filtered(selector) selection
          gets the child elements of each element in the Selection, filtered by the specified selector
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        contents(selector) selection
          gets the children of each element in the Selection, including text and comment nodes
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        find(selector) selection
          gets the descendants of each element in the current set of matched elements, filtered by a selector
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        filter(selector) selection
          filter reduces the set of matched elements to those that match the selector string
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        get(i) selection
          retrieves the underlying node at the specified index. alias: eq
          params:
            i int
              numerical index of node to get
        has(selector) selection
          reduces the set of matched elements to those that have a descendant that matches the selector
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        parent(selector) selection
          gets the parent of each element in the Selection
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        parents_until(selector) selection
          gets the ancestors of each element in the Selection, up to but not including the element matched by the selector
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        siblings() selection
          gets the siblings of each element in the Selection
        text() string
          gets the combined text contents of each element in the set of matched elements, including descendants
        first(selector) selection
          gets the first element of the selection
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        last() selection
          gets the last element of the selection
          params:
            selector string
              a query selector string to filter the current selection, returning a new selection
        len() int
          returns the number of the nodes in the selection
        eq(i) selection
          gets the element at index i of the selection
          params:
            i int
              numerical index of node to get

Index

Constants

View Source
const ModuleName = "html.star"

ModuleName defines the expected name for this Module when used in starlark's load() function, eg: load('html.star', 'html')

Variables

This section is empty.

Functions

func AsString

func AsString(x starlark.Value) (string, error)

AsString unquotes a starlark string value

func LoadModule

func LoadModule() (starlark.StringDict, error)

LoadModule loads the html module

func NewDocument

func NewDocument(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

NewDocument creates a starlark selection from input text

func NewSelectionStruct

func NewSelectionStruct(s *goquery.Selection) *starlarkstruct.Struct

NewSelectionStruct creates a starlark struct from a goquery selection

Types

type Selection

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

Selection is a wrapper for a goquery selection mapping to starlark values

func (*Selection) Attr

func (s *Selection) Attr(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Attr gets the specified attribute's value for the first element in the Selection. To get the value for each element individually, use a looping construct such as Each or Map method

func (*Selection) Children

func (s *Selection) Children(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Children gets the child elements of each element in the Selection. It returns a new Selection object containing these elements

func (*Selection) ChildrenFiltered

func (s *Selection) ChildrenFiltered(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

ChildrenFiltered gets the child elements of each element in the Selection, filtered by the specified selector. It returns a new Selection object containing these elements

func (*Selection) Contents

func (s *Selection) Contents(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Contents gets the children of each element in the Selection, including text and comment nodes. It returns a new Selection object containing these elements

func (*Selection) Eq

func (s *Selection) Eq(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Eq gets the element i of the selection

func (*Selection) Filter

func (s *Selection) Filter(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Filter reduces the set of matched elements to those that match the selector string. It returns a new Selection object for this subset of matching elements

func (*Selection) Find

func (s *Selection) Find(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Find gets the descendants of each element in the current set of matched elements, filtered by a selector. It returns a new Selection object containing these matched element

func (*Selection) First

func (s *Selection) First(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

First gets the first element of the selection

func (*Selection) Get

func (s *Selection) Get(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Get retrieves the underlying node at the specified index. Get without parameter is not implemented, since the node array is available on the Selection object

func (*Selection) Has

func (s *Selection) Has(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Has reduces the set of matched elements to those that have a descendant that matches the selector. It returns a new Selection object with the matching elements

func (*Selection) Last

func (s *Selection) Last(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Last gets the last element of the selection

func (*Selection) Len

func (s *Selection) Len(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Len returns the length of the nodes in the selection

func (*Selection) Parent

func (s *Selection) Parent(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Parent gets the parent of each element in the Selection. It returns a new Selection object containing the matched elements

func (*Selection) ParentsUntil

func (s *Selection) ParentsUntil(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

ParentsUntil gets the ancestors of each element in the Selection, up to but not including the element matched by the selector. It returns a new Selection object containing the matched elements

func (*Selection) Siblings

func (s *Selection) Siblings(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Siblings gets the siblings of each element in the Selection. It returns a new Selection object containing the matched elements

func (*Selection) Struct

func (s *Selection) Struct() *starlarkstruct.Struct

Struct returns a starlark struct of methods

func (*Selection) Text

func (s *Selection) Text(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Text gets the combined text contents of each element in the set of matched elements, including their descendants

Jump to

Keyboard shortcuts

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