Skip to content

typelate/dom

Repository files navigation

dom Go Reference

Pure Go implementation of the WHATWG DOM backed by golang.org/x/net/html. CSS selectors are provided by andybalholm/cascadia.

Packages

Package Description
dom Implements Document, Element, Text, and DocumentFragment using html.Node.
spec Interfaces matching the WHATWG DOM spec. Shared by dom and browser.
domtest Test helpers that parse HTML strings or http.Response bodies into spec types.
browser Experimental. Implements spec interfaces via syscall/js for WASM.

Example

func TestGreeting(t *testing.T) {
	res := httptest.NewRecorder()
	handler.ServeHTTP(res, httptest.NewRequest("GET", "/", nil))

	doc := domtest.ParseResponseDocument(t, res.Result())
	heading := doc.QuerySelector("h1")
	if heading == nil {
		t.Fatal("expected an h1")
	}
	if got := heading.TextContent(); got != "Hello" {
		t.Errorf("heading = %q, want %q", got, "Hello")
	}
}

About

This project has document object model (DOM) inspired wrappers around the https://golang.org/x/net/html package.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages