modulepackage
0.0.0-20230515143342-73569d674e1c
Repository: https://github.com/go-shiori/dom.git
Documentation: pkg.go.dev
# README
DOM
DOM is a Go package for manipulating HTML node. The methods that exist in this package has similar name and purpose as the DOM manipulation methods in JS, which make it useful when porting code from JS to Go. Currently it used in warc
and go-readability
.
Installation
To install this package, just run go get
:
go get -u -v github.com/go-shiori/dom
Licenses
DOM is distributed under MIT license, which means you can use and modify it however you want. However, if you make an enhancement for it, if possible, please send a pull request. If you like this project, please consider donating to me either via PayPal or Ko-Fi.
# Functions
AppendChild adds a node to the end of the list of children of a specified parent node.
ChildNodes returns list of a node's direct children.
Children returns an HTMLCollection of the direct child elements of Node.
ClassName returns the value of the class attribute of the specified element.
Clone returns a clone of the node and (if specified) its children.
CreateElement creates a new ElementNode with specified tag.
CreateTextNode creates a new Text node.
No description provided by the author
DocumentElement returns the Element that is the root element of the document.
FastParse parses html.Node from the specified reader without caring about text encoding.
FirstElementChild returns the object's first child Element, or nil if there are no child elements.
ForEachNode iterates over a NodeList and runs fn on each node.
GetAllNodesWithTag is wrapper for GetElementsByTagName() which allow to get several tags at once.
GetAttribute returns the value of a specified attribute on the element.
GetElementByID returns a Node object representing the element whose id property matches the specified string.
GetElementsByClassName returns an array of all child elements which have all of the given class name(s).
GetElementsByTagName returns a collection of all elements in the document with the specified tag name, as an array of Node object.
HasAttribute returns a Boolean value indicating whether the specified node has the specified attribute or not.
ID returns the value of the id attribute of the specified element.
IncludeNode determines if node is included inside nodeList.
InnerHTML returns the HTML content (inner HTML) of an element.
InnerText in JS used to capture text from an element while excluding text from hidden children.
IsVoidElement check whether a node can have any contents or not.
NextElementSibling returns the Element immediately following the specified one in its parent's children list, or nil if the specified Element is the last one in the list.
OuterHTML returns an HTML serialization of the element and its descendants.
Parse parses html.Node from the specified reader while converting the character encoding into UTF-8.
PrependChild works like AppendChild() except it adds a node to the beginning of the list of children of a specified parent node.
PreviousElementSibling returns the the Element immediately prior to the specified one in its parent's children list, or null if the specified element is the first one in the list.
QuerySelector returns the first document's element that match the specified group of selectors.
QuerySelectorAll returns array of document's elements that match the specified group of selectors.
RemoveAttribute removes attribute with given name.
RemoveNodes iterates over a NodeList, calls `filterFn` for each node and removes node if function returned `true`.
ReplaceChild replaces a child node within the given (parent) node.
SetAttribute sets attribute for node.
SetInnerHTML sets inner HTML of the specified node.
SetTextContent sets the text content of the specified node.
TagName returns the tag name of a Node.
TextContent returns the text content of the specified node, and all its descendants.