Documentation
¶
Overview ¶
Package html works on top of the DOM to implement specific HTML elements.
The fundamental structure is implemented in package dom.
Index ¶
- Constants
- Variables
- func NewDOMParser() domParser
- func ParseFragment(ownerDocument dom.Document, reader io.Reader) (dom.DocumentFragment, error)
- type BaseRules
- type BrowsingContext
- type Clock
- type DOMStringList
- type DOMStringMap
- type ElementSteps
- type FormData
- func (d *FormData) AddElement(e dom.Element)
- func (d *FormData) All() iter.Seq2[string, FormDataValue]
- func (d *FormData) Append(name string, value FormDataValue)
- func (d *FormData) Delete(name string)
- func (d *FormData) Get(name string) FormDataValue
- func (d *FormData) GetAll(name string) []FormDataValue
- func (d *FormData) GetReader() io.ReadCloser
- func (d *FormData) Has(name string) bool
- func (d *FormData) Keys() []string
- func (d *FormData) QueryString() string
- func (d *FormData) Set(name string, value FormDataValue)
- func (d *FormData) Values() []FormDataValue
- type FormDataEntry
- type FormDataEventInit
- type FormDataValue
- type FormEvent
- type FormSubmitEvent
- type GetReader
- type HTMLAnchorElement
- type HTMLButtonElement
- type HTMLDocument
- type HTMLElement
- type HTMLFormElement
- type HTMLHyperlinkElementUtils
- type HTMLInputElement
- type HTMLLabelElement
- type HTMLOrSVGElement
- type HTMLScriptElement
- type HTMLTemplateElement
- type History
- func (h *History) Back() error
- func (h *History) Forward() error
- func (h *History) Go(relative int) error
- func (h History) Length() int
- func (h *History) PushState(state HistoryState, href string) error
- func (h *History) ReplaceState(state HistoryState, href string) error
- func (h History) State() HistoryState
- type HistoryState
- type Location
- type PopStateEventInit
- type Predicate
- type ScriptContext
- type ScriptHost
- type SetActiveElementer
- type SubmitEventInit
- type TemplateElementRules
- type Window
- type WindowOption
- type WindowOptionFunc
- type WindowOptions
Constants ¶
const HistoryEventPopState = "popstate"
Variables ¶
var ElementMap = map[atom.Atom]ElementSteps{ atom.Template: TemplateElementRules{}, }
var ErrTooManyRedirects = errors.New("Too many redirects")
Functions ¶
func NewDOMParser ¶
func NewDOMParser() domParser
func ParseFragment ¶ added in v0.3.0
Types ¶
type BrowsingContext ¶ added in v0.5.1
type BrowsingContext interface {
// Logger returns the currently configured logger for the window. Returns
// nil if no instance is created.
Logger() *slog.Logger
HTTPClient() http.Client
LocationHREF() string
}
Describes a current browser context
type DOMStringList ¶ added in v0.2.0
type DOMStringMap ¶ added in v0.5.0
DOMStringMap provides access to data-* attributes of an HTML or SVG element. In JavaScript, it is a dictionary-like object wrapping content with a "data-" prefix, converting kebab-case to camel-case, and stripping the prefix.
See also: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
func (DOMStringMap) Delete ¶ added in v0.5.0
func (m DOMStringMap) Delete(key string)
func (DOMStringMap) Get ¶ added in v0.5.0
func (m DOMStringMap) Get(key string) (val string, exists bool)
func (DOMStringMap) Set ¶ added in v0.5.0
func (m DOMStringMap) Set(key string, val string)
type ElementSteps ¶
type FormData ¶
type FormData struct {
Entries []FormDataEntry
}
func NewFormData ¶
func NewFormData() *FormData
func NewFormDataForm ¶
func NewFormDataForm(form HTMLFormElement) *FormData
func (*FormData) AddElement ¶
func (*FormData) Append ¶
func (d *FormData) Append(name string, value FormDataValue)
func (*FormData) Get ¶
func (d *FormData) Get(name string) FormDataValue
func (*FormData) GetAll ¶
func (d *FormData) GetAll(name string) []FormDataValue
func (*FormData) GetReader ¶
func (d *FormData) GetReader() io.ReadCloser
func (*FormData) QueryString ¶
QueryString returns the formdata as a &-separated URL encoded key-value pair.
func (*FormData) Set ¶
func (d *FormData) Set(name string, value FormDataValue)
func (*FormData) Values ¶
func (d *FormData) Values() []FormDataValue
type FormDataEntry ¶
type FormDataEntry struct {
Name string
Value FormDataValue
}
type FormDataEventInit ¶ added in v0.4.0
type FormDataEventInit struct {
FormData *FormData
}
type FormDataValue ¶
type FormDataValue string // TODO Blob/file
func NewFormDataValueString ¶
func NewFormDataValueString(value string) FormDataValue
type GetReader ¶
type GetReader interface {
GetReader() io.ReadCloser
}
type HTMLAnchorElement ¶
type HTMLAnchorElement interface {
HTMLElement
HTMLHyperlinkElementUtils
Target() string
SetTarget(string)
Download() string
SetDownload(string)
Ping() string
SetPing(string)
Rel() string
SetRel(string)
RelList() dom.DOMTokenList
Hreflang() string
SetHreflang(string)
Type() string
SetType(string)
Text() string
SetText(string)
ReferrerPolicy() string
SetReferrerPolicy(string)
}
func NewHTMLAnchorElement ¶
func NewHTMLAnchorElement(ownerDoc HTMLDocument) HTMLAnchorElement
type HTMLButtonElement ¶
type HTMLButtonElement interface {
HTMLElement
Type() string
SetType(val string)
}
func NewHTMLButtonElement ¶
func NewHTMLButtonElement(ownerDocument HTMLDocument) HTMLButtonElement
type HTMLDocument ¶
func NewHTMLDocument ¶
func NewHTMLDocument(window Window) HTMLDocument
NewHTMLDocument creates an HTML document for an about:blank page.
The resulting document has an outer HTML similar to this, but there are no guarantees about the actual content.
<html><head></head><body><h1>Gost-DOM</h1></body></html>
type HTMLElement ¶
type HTMLElement interface {
dom.Element
Renderer
ChildrenRenderer
HTMLOrSVGElement
Click()
// contains filtered or unexported methods
}
func NewHTMLElement ¶
func NewHTMLElement(tagName string, ownerDocument HTMLDocument) HTMLElement
func NewHTMLScriptElement ¶
func NewHTMLScriptElement(ownerDocument HTMLDocument) HTMLElement
type HTMLFormElement ¶
type HTMLFormElement interface {
HTMLElement
Action() string
SetAction(val string)
Method() string
SetMethod(value string)
Elements() dom.NodeList
Submit() error
RequestSubmit(submitter dom.Element) error
}
func NewHtmlFormElement ¶
func NewHtmlFormElement(ownerDocument HTMLDocument) HTMLFormElement
type HTMLHyperlinkElementUtils ¶ added in v0.2.0
type HTMLHyperlinkElementUtils interface {
fmt.Stringer
Href() string
SetHref(string)
Origin() string
Protocol() string
SetProtocol(string)
Username() string
SetUsername(string)
Password() string
SetPassword(string)
Host() string
SetHost(string)
Hostname() string
SetHostname(string)
Port() string
SetPort(string)
Pathname() string
SetPathname(string)
Search() string
SetSearch(string)
Hash() string
SetHash(string)
}
type HTMLInputElement ¶
type HTMLInputElement interface {
HTMLElement
Type() string
SetType(value string)
Name() string
CheckValidity() bool
Checked() bool
SetChecked(bool)
}
func NewHTMLInputElement ¶
func NewHTMLInputElement(ownerDocument HTMLDocument) HTMLInputElement
type HTMLLabelElement ¶ added in v0.5.6
type HTMLLabelElement interface {
HTMLElement
HTMLFor() string
SetHTMLFor(string)
}
func NewHTMLLabelElement ¶ added in v0.5.6
func NewHTMLLabelElement(ownerDoc HTMLDocument) HTMLLabelElement
type HTMLOrSVGElement ¶ added in v0.5.0
type HTMLScriptElement ¶ added in v0.1.1
type HTMLScriptElement = HTMLElement
type HTMLTemplateElement ¶
type HTMLTemplateElement interface {
HTMLElement
Content() dom.DocumentFragment
}
func NewHTMLTemplateElement ¶
func NewHTMLTemplateElement(ownerDocument HTMLDocument) HTMLTemplateElement
type History ¶
type History struct {
// contains filtered or unexported fields
}
History implements the History API
Note: Currently, state is represented by string, but may change to a different type representing a JSON object.
func (*History) Back ¶
Back calls Go(-1).
See also: https://developer.mozilla.org/en-US/docs/Web/API/History/back
func (*History) Forward ¶
Forward calls Go(1).
See also: https://developer.mozilla.org/en-US/docs/Web/API/History/forward
func (*History) Go ¶
Go moves back or forward through the history, possibly reloading the page if necessary. A negative value goes back in history; a positive value moves forward if possible. A value of 0 will trigger a reload.
See also: https://developer.mozilla.org/en-US/docs/Web/API/History/go
func (History) Length ¶
Length returns the number of entries in the history. When navigating back, the length doesn't change, as they last viewed page is still in history.
Navigating to a new location truncates future history later than the current page.
func (*History) PushState ¶
func (h *History) PushState(state HistoryState, href string) error
ReplaceState will update the current Location and push this as a new history entry without making a new request.
The function corresponds to replaceState on the History API with the following notes. If href is empty, the URL will not be updated; as if the argument was not specified in the JS API.
func (*History) ReplaceState ¶
func (h *History) ReplaceState(state HistoryState, href string) error
ReplaceState will update the current Location and history entry without making a new request.
The function corresponds to replaceState on the History API with the following notes. If href is empty, the URL will not be updated; as if the argument was not specified in the JS API.
func (History) State ¶
func (h History) State() HistoryState
State returns the state for the current page.
type HistoryState ¶
type HistoryState = htmlinterfaces.HistoryState
const EMPTY_STATE HistoryState = ""
type Location ¶ added in v0.2.0
type Location interface {
fmt.Stringer
Href() string
SetHref(string)
Origin() string
Protocol() string
SetProtocol(string)
Host() string
SetHost(string)
Hostname() string
SetHostname(string)
Port() string
SetPort(string)
Pathname() string
SetPathname(string)
Search() string
SetSearch(string)
Hash() string
SetHash(string)
AncestorOrigins() DOMStringList
Assign(string) error
Replace(string) error
Reload() error
}
type PopStateEventInit ¶ added in v0.4.0
type PopStateEventInit struct {
State HistoryState
}
The PopStateEvent is emitted after navigating to the same document, and will contain possible state passed to History.ReplaceState or History.PushState.
See also: https://developer.mozilla.org/en-US/docs/Web/API/PopStateEvent
type ScriptContext ¶
type ScriptContext interface {
// Run a script, and convert the result to a Go type. Only use this if you
// need the return value, otherwise call Run.
//
// If the evaluated JS value cannot be converted to a Go value, an error is
// returned.
Eval(script string) (any, error)
// Run a script. This is should be used instead of eval when the return value
// is not needed, as eval returns an error when the return value cannot be
// converted to a go type.
Run(script string) error
Clock() Clock
Close()
}
type ScriptHost ¶
type ScriptHost interface {
NewContext(window Window) ScriptContext
Close()
}
type SetActiveElementer ¶ added in v0.5.0
type SubmitEventInit ¶ added in v0.4.0
type TemplateElementRules ¶
type TemplateElementRules struct{ BaseRules }
func (TemplateElementRules) AppendChild ¶
type Window ¶
type Window interface {
event.EventTarget
BrowsingContext
entity.ObjectIder
Document() dom.Document
Close()
Clock() Clock
LoadHTML(string) error // TODO: Remove, for testing
// Eval calls [ScriptContext.Eval]
Eval(string) (any, error)
// Run calls [ScriptContext.Run]
Run(string) error
ScriptContext() ScriptContext
Location() Location
History() *History
ParseFragment(ownerDocument dom.Document, reader io.Reader) (dom.DocumentFragment, error)
// contains filtered or unexported methods
}
func NewWindow ¶
func NewWindow(windowOptions ...WindowOption) Window
func NewWindowReader ¶
func NewWindowReader(reader io.Reader, windowOptions ...WindowOption) (Window, error)
NewWindowReader will create a new window and load parse the HTML from the reader. If there is an error reading from the stream, or parsing the DOM, an error is returned.
If this function returns without an error, the DOM will have been parsed and the DOMContentLoaded event has been dispached on the dom.Document
func OpenWindowFromLocation ¶
func OpenWindowFromLocation(location string, windowOptions ...WindowOption) (Window, error)
type WindowOption ¶
type WindowOption interface {
Apply(options *WindowOptions)
}
type WindowOptionFunc ¶
type WindowOptionFunc func(*WindowOptions)
func WindowOptionHTTPClient ¶ added in v0.5.8
func WindowOptionHTTPClient(client http.Client) WindowOptionFunc
func WindowOptionHost ¶ added in v0.3.0
func WindowOptionHost(host ScriptHost) WindowOptionFunc
func WindowOptionLocation ¶
func WindowOptionLocation(location string) WindowOptionFunc
func (WindowOptionFunc) Apply ¶
func (f WindowOptionFunc) Apply(options *WindowOptions)
type WindowOptions ¶
type WindowOptions struct {
ScriptHost
HttpClient http.Client
BaseLocation string
Logger *slog.Logger
}
func (WindowOptions) Apply ¶
func (o WindowOptions) Apply(options *WindowOptions)
Source Files
¶
- dom_parser.go
- dom_string_list_generated.go
- dom_string_map.go
- form_data.go
- history.go
- html_anchor_element.go
- html_anchor_element_generated.go
- html_button_element.go
- html_document.go
- html_element.go
- html_form_element.go
- html_hyper_link_element_utils_generated.go
- html_input_element.go
- html_label_element.go
- html_or_svg_element_generated.go
- html_script_element.go
- html_template_element.go
- location.go
- location_generated.go
- package.go
- window.go