goqs

package module
v0.0.0-...-bac7700 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 6 Imported by: 0

README

goQuerySelector

Go Report Card codecov

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClassSet

type ClassSet map[string]bool

ClassSet is a set type with string elements. It has the following methods: Insert(string), Remove(string), Has(string)->bool, Slice()->[]string

func MakeClassSet

func MakeClassSet(classes []string) ClassSet

MakeClassSet turns a slice of strings into a non-repeating set containing each element from the slice

func (ClassSet) Has

func (set ClassSet) Has(class string) bool

Has returns if a class exists inside of a set

func (ClassSet) Insert

func (set ClassSet) Insert(class string)

Insert puts the string class into the set. If the class is already there, there will be no effect.

func (ClassSet) Remove

func (set ClassSet) Remove(class string)

Remove takes a class out of a set. If the class is not there, there will be no effect.

func (ClassSet) Slice

func (set ClassSet) Slice() []string

Slice returns a slice containing each element that resides in the set

type Document

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

Document stores the contents of an html page in order, and all of the top level elements

func ParseHTML

func ParseHTML(htmlStr string) (Document, error)

ParseHTML takes an html string and parses the html into elements

func ParseHTMLFile

func ParseHTMLFile(filePath string) (Document, error)

ParseHTMLFile takes a filepath and parses the html inside

func (*Document) QuerySelector

func (doc *Document) QuerySelector(pattern string) (*HTMLElement, error)

QuerySelector returns a pointer to the first element satisfying the criteria in the input string found in the html document. The function uses CSS selectors like in JavaScript. For reference, follow the link to https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors

type EmptyStackError

type EmptyStackError struct {
}

EmptyStackError is an error type that is thrown when an element from a HTMLStack is attempted to be accessed from an empty stack

func (EmptyStackError) Error

func (e EmptyStackError) Error() string

type HTMLElement

type HTMLElement struct {
	Raw     html.Token
	Tag, ID string

	ClassList   ClassSet
	Attributes  map[string]string
	Children    []*HTMLElement
	IsSingleTag bool
	TokenType   html.TokenType
	// contains filtered or unexported fields
}

HTMLElement holds the data for the html tags parsed from the file

func (*HTMLElement) QuerySelector

func (elem *HTMLElement) QuerySelector(pattern string) (*HTMLElement, error)

QuerySelector returns a pointer to the first element satisfying the criteria in the input string. The function uses CSS selectors like in JavaScript. For reference, follow the link to https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors

func (*HTMLElement) String

func (elem *HTMLElement) String() string

func (*HTMLElement) Text

func (elem *HTMLElement) Text() string

Text formats the stored text objects into a proper string

type HTMLStack

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

HTMLStack is a stack data structure that can hold HTMLElement objects

func MakeStack

func MakeStack() HTMLStack

MakeStack returns a default HTMLStack object with a nil root and 0 length

func (*HTMLStack) Empty

func (stack *HTMLStack) Empty() bool

Empty returns whether or not the stack is empty

func (*HTMLStack) Pop

func (stack *HTMLStack) Pop() (*HTMLElement, error)

Pop removes the top element and returns it

func (*HTMLStack) Push

func (stack *HTMLStack) Push(element *HTMLElement)

Push adds onto the top of the stack

func (*HTMLStack) Size

func (stack *HTMLStack) Size() int

Size returns the number of elements in the current stack

func (*HTMLStack) Top

func (stack *HTMLStack) Top() (*HTMLElement, error)

Top returns the top element if it, or gives an error if stack is empty

type HTMLStackNode

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

HTMLStackNode is a linked list node that is used in HTMLStack

type ParsingError

type ParsingError struct{}

ParsingError occurs when an parsing fails or an html.ErrorToken appears

func (ParsingError) Error

func (ParsingError) Error() string

type PatternError

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

PatternError is thrown when a parsed querySelector pattern's syntax is unrecognized

func (PatternError) Error

func (e PatternError) Error() string

Jump to

Keyboard shortcuts

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