gq

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

README

References

Documentation

Overview

Package gq the goquery parser

Index

Constants

View Source
const Key string = "gq"

Key the gq parser register key.

Variables

This section is empty.

Functions

func Attr added in v0.3.0

func Attr(_ *plugin.Context, content any, args ...string) (any, error)

Attr gets the specified attribute's value for the first element in the Selection. The first argument is the name of the attribute, the second is the default value

func Child added in v0.3.0

func Child(_ *plugin.Context, content any, args ...string) (any, error)

Child gets the child elements of each element in the Selection. If present the selector will return filtered by the specified selector.

func Get added in v0.3.0

func Get(ctx *plugin.Context, _ any, args ...string) (any, error)

Get returns the value associated with this context for key, or nil if no value is associated with key.

func Href added in v0.3.0

func Href(ctx *plugin.Context, content any, _ ...string) (any, error)

Href gets the href attribute's value, if URL is not absolute returns the absolute URL.

func Html added in v0.3.0

func Html(_ *plugin.Context, content any, args ...string) (any, error)

Html the first argument is outer. If true returns the outer HTML rendering of the first item in the selection - that is, the HTML including the first element's tag and attributes, or gets the HTML contents of the first element in the set of matched elements. It includes text and comment nodes;

func Join added in v0.3.0

func Join(ctx *plugin.Context, content any, args ...string) (any, error)

Join the text with the separator, if not present separator uses the default separator ", ".

func NewGoQueryParser added in v0.3.0

func NewGoQueryParser(funcs FuncMap) parser.Parser

NewGoQueryParser creates a new goquery Parser with the given FuncMap.

func Next added in v0.3.0

func Next(_ *plugin.Context, content any, args ...string) (any, error)

Next gets the immediately following sibling of each element in the Selection. If present selector gets all following siblings of each element up to but not including the element matched by the selector.

func Parent added in v0.3.0

func Parent(_ *plugin.Context, content any, args ...string) (any, error)

Parent gets the parent of each element in the Selection. if present the selector will return filtered by a selector.

func Parents added in v0.3.0

func Parents(_ *plugin.Context, content any, args ...string) (any, error)

Parents gets the ancestors of each element in the current Selection. if present the selector will return filtered by a selector.

func Prefix added in v0.3.0

func Prefix(_ *plugin.Context, content any, args ...string) (ret any, err error)

func Prev added in v0.3.0

func Prev(_ *plugin.Context, content any, args ...string) (any, error)

Prev gets the immediately preceding sibling of each element in the Selection. If present selector gets all preceding siblings of each element up to but not including the element matched by the selector.

func Set added in v0.3.0

func Set(ctx *plugin.Context, content any, args ...string) (any, error)

Set value associated with key is val. The first argument is the key, and the second argument is value. if the value is present will store the content.

func Slice added in v0.3.0

func Slice(_ *plugin.Context, content any, args ...string) (any, error)

Slice reduces the set of matched elements to a subset specified by a range of indices. The start index is 0-based and indicates the index of the first element to select. The end index is 0-based and indicates the index at which the elements stop being selected (the end index is not selected).

If the end index is not specified reduces the set of matched elements to the one at the specified start index.

The indices may be negative, in which case they represent an offset from the end of the selection.

func Suffix added in v0.3.0

func Suffix(_ *plugin.Context, content any, args ...string) (ret any, err error)

func Text added in v0.3.0

func Text(_ *plugin.Context, content any, _ ...string) (any, error)

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

Types

type FuncMap added in v0.3.0

type FuncMap map[string]GFunc

FuncMap is the type of the map defining the mapping from names to functions.

type GFunc added in v0.3.0

type GFunc func(ctx *plugin.Context, content any, args ...string) (any, error)

GFunc is the type of gq parse function.

type Parser

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

Parser the goquery parser

func (*Parser) GetElement

func (p *Parser) GetElement(ctx *plugin.Context, content any, arg string) (ret string, err error)

GetElement gets the element of the content with the given arguments.

content := `<ul><li>1</li><li>2</li></ul>` GetElement(ctx, content, "ul li") returns "<li>1</li>\n<li>2</li>"

func (*Parser) GetElements

func (p *Parser) GetElements(ctx *plugin.Context, content any, arg string) (ret []string, err error)

GetElements gets the elements of the content with the given arguments.

content := `<ul><li>1</li><li>2</li></ul>` GetElements(ctx, content, "ul li") returns []string{"<li>1</li>", "<li>2</li>"}

func (*Parser) GetString

func (p *Parser) GetString(ctx *plugin.Context, content any, arg string) (ret string, err error)

GetString gets the string of the content with the given arguments.

content := `<ul><li>1</li><li>2</li></ul>` GetString(ctx, content, "ul li") returns "1\n2"

func (*Parser) GetStrings

func (p *Parser) GetStrings(ctx *plugin.Context, content any, arg string) (ret []string, err error)

GetStrings gets the strings of the content with the given arguments.

content := `<ul><li>1</li><li>2</li></ul>` GetStrings(ctx, content, "ul li") returns []string{"1", "2"}

Jump to

Keyboard shortcuts

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