Documentation ¶
Overview ¶
Package dom will some day provide utilities for HTMLbook DOMs.
Status ¶
Early draft—API may change frequently. Please stay patient.
Overview ¶
HTMLbook is the core DOM of our documents. Background for this decision can be found under https://www.balisage.net/Proceedings/vol10/print/Kleinfeld01/BalisageVol10-Kleinfeld01.html and http://radar.oreilly.com/2013/09/html5-is-the-future-of-book-authorship.html
Excerpt: "In this paper, I argue that HTML5 offers unique advantages to authors and publishers in comparison to both traditional word processing and desktop publishing tools like Microsoft Word and Adobe InDesign, as well as other markup vocabularies like DocBook and AsciiDoc. I also consider the drawbacks currently inherent in the HTML5 standard with respect to representing long-form, structured text content, and the challenges O’Reilly has faced in adopting the standard as the new source format for its toolchain. Finally, I discuss how O’Reilly has surmounted these challenges by developing HTMLBook, a new open, HTML5-based XML standard expressly designed for the authoring and production of both print and digital book content."
For an in-depth description of HTMLbook please refer to https://oreillymedia.github.io/HTMLBook/.
Tree Implementation ¶
Styling and layout of HTML/CSS involves a lot of operations on different trees. We implement the various trees on top of a general purpose tree type (package engine/tree), which offers concurrent operations to manipluate tree nodes.
In a fully object oriented programming language we would subclass this tree type for every type of tree in use (styled tree, layout tree, render tree), but in Go we resort to composition, thus including a generic tree node in every node (sub-)type. The downside of this approach is that we will have to provide an adapter for every node sub-type to return the sub-type from the generic type.
BSD License ¶
Copyright (c) 2017–20, Norbert Pillmayer ¶
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of this software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index ¶
- Constants
- Variables
- func NodeAsTreeNode(domnode w3cdom.Node) (*tree.Node, bool)
- func T() tracing.Trace
- type W3CAttr
- func (a *W3CAttr) Attributes() w3cdom.NamedNodeMap
- func (a *W3CAttr) ChildNodes() w3cdom.NodeList
- func (a *W3CAttr) Children() w3cdom.NodeList
- func (a *W3CAttr) ComputedStyles() w3cdom.ComputedStyles
- func (a *W3CAttr) FirstChild() w3cdom.Node
- func (a *W3CAttr) HasAttributes() bool
- func (a *W3CAttr) HasChildNodes() bool
- func (a *W3CAttr) Key() string
- func (a *W3CAttr) Namespace() string
- func (a *W3CAttr) NextSibling() w3cdom.Node
- func (a *W3CAttr) NodeName() string
- func (a *W3CAttr) NodeType() html.NodeType
- func (a *W3CAttr) NodeValue() string
- func (a *W3CAttr) ParentNode() w3cdom.Node
- func (a *W3CAttr) TextContent() (string, error)
- func (a *W3CAttr) Value() string
- type W3CMap
- type W3CNode
- func (w *W3CNode) Attributes() w3cdom.NamedNodeMap
- func (w *W3CNode) ChildNodes() w3cdom.NodeList
- func (w *W3CNode) Children() w3cdom.NodeList
- func (w *W3CNode) ComputedStyles() w3cdom.ComputedStyles
- func (w *W3CNode) FirstChild() w3cdom.Node
- func (w *W3CNode) HTMLNode() *html.Node
- func (w *W3CNode) HasAttributes() bool
- func (w *W3CNode) HasChildNodes() bool
- func (w *W3CNode) IsDocument() bool
- func (w *W3CNode) IsRoot() bool
- func (w *W3CNode) NextSibling() w3cdom.Node
- func (w *W3CNode) NodeName() string
- func (w *W3CNode) NodeType() html.NodeType
- func (w *W3CNode) NodeValue() string
- func (w *W3CNode) ParentNode() w3cdom.Node
- func (w *W3CNode) TextContent() (string, error)
- func (w *W3CNode) Walk() *tree.Walker
- type W3CNodeList
Constants ¶
const AttrNode = html.NodeType(77)
AttrNode is an additional node type, complementing those defined in standard-package html.
Variables ¶
var ErrNotAStyledNode = fmt.Errorf("Tree node is not a styled node")
ErrNotAStyledNode is returned if a tree node does not belong to a styled tree node.
var NodeIsText = func(n *tree.Node, unused *tree.Node) (match *tree.Node, err error) { domnode, err := NodeFromTreeNode(n) if err != nil { return nil, err } if domnode.NodeName() == "#text" { return n, nil } return nil, nil }
NodeIsText is a predicate to match text-nodes of a DOM. It is intended to be used in a tree.Walker.
Functions ¶
func NodeAsTreeNode ¶
NodeAsTreeNode returns the underlying tree.Node from a DOM node.
Types ¶
type W3CAttr ¶
type W3CAttr struct {
// contains filtered or unexported fields
}
A W3CAttr represents a single attribute of an element Node.
func (*W3CAttr) Attributes ¶
func (a *W3CAttr) Attributes() w3cdom.NamedNodeMap
Attributes returns nil
func (*W3CAttr) ComputedStyles ¶
func (a *W3CAttr) ComputedStyles() w3cdom.ComputedStyles
ComputedStyles gets null-styles
func (*W3CAttr) TextContent ¶
TextContent returns an empty string
type W3CMap ¶
type W3CMap struct {
// contains filtered or unexported fields
}
A W3CMap represents a key-value map
func (*W3CMap) GetNamedItem ¶
GetNamedItem returns the attribute with key key.
type W3CNode ¶
type W3CNode struct {
// contains filtered or unexported fields
}
A W3CNode is common type from which various types of DOM API objects inherit. This allows these types to be treated similarly.
func FromHTMLParseTree ¶
func FromHTMLParseTree(h *html.Node, css cssom.StyleSheet) *W3CNode
FromHTMLParseTree returns a W3C DOM from parsed HTML and an optional style sheet.
func NodeFromStyledNode ¶
func NodeFromStyledNode(sn *styledtree.StyNode) *W3CNode
NodeFromStyledNode creates a new DOM node from a styled node.
func NodeFromTreeNode ¶
NodeFromTreeNode creates a new DOM node from a tree node, which should be the inner node of a styledtree.Node.
func (*W3CNode) Attributes ¶
func (w *W3CNode) Attributes() w3cdom.NamedNodeMap
Attributes property returns a collection of all attribute nodes registered to the specified node. It is a NamedNodeMap, not an array.
func (*W3CNode) ChildNodes ¶
ChildNodes read-only property returns a live NodeList of child nodes of the given element.
func (*W3CNode) Children ¶
Children is a read-only property that returns a node list which contains all of the child *elements* of the node upon which it was called
func (*W3CNode) ComputedStyles ¶
func (w *W3CNode) ComputedStyles() w3cdom.ComputedStyles
ComputedStyles returns a map of style properties for a given (stylable) Node.
func (*W3CNode) FirstChild ¶
FirstChild read-only property returns the node's first child in the tree, or nil if the node has no children.
func (*W3CNode) HasAttributes ¶
HasAttributes returns a boolean indicating whether the current element has any attributes or not.
func (*W3CNode) HasChildNodes ¶
HasChildNodes method returns a boolean value indicating whether the given Node has child nodes or not.
func (*W3CNode) IsDocument ¶
IsDocument returns wether this node is the document node of the styled tree.
func (*W3CNode) NextSibling ¶
NextSibling read-only property returns the node immediately following the specified one in their parent's childNodes, or returns nil if the specified node is the last child in the parent element.
func (*W3CNode) NodeName ¶
NodeName read-only property returns the name of the current Node as a string.
Node NodeName value ------------+---------------------------- Attr The value of Attr.name Document "#document" Element The value of Element.TagName Text "#text"
func (*W3CNode) NodeType ¶
NodeType returns the type of the underlying HTML node, something like html.ElementNode, html.TextNode, etc.
func (*W3CNode) NodeValue ¶
NodeValue returns textual content for text/CData-Nodes, and an empty string for any other Node type.
func (*W3CNode) ParentNode ¶
ParentNode read-only property returns the parent of the specified node in the DOM tree.
func (*W3CNode) TextContent ¶
TextContent property of the Node interface represents the text content of the node and its descendants.
This implementation will include error strings in the text output, if errors occur. They will be flagged as "(ERROR: ... )".
type W3CNodeList ¶
type W3CNodeList struct {
// contains filtered or unexported fields
}
A W3CNodeList is a type for a list of nodes
func (*W3CNodeList) Item ¶
func (wl *W3CNodeList) Item(i int) w3cdom.Node
Item returns the i.th Node
func (*W3CNodeList) Length ¶
func (wl *W3CNodeList) Length() int
Length returns the number of Nodes in a list
func (*W3CNodeList) String ¶
func (wl *W3CNodeList) String() string
Directories ¶
Path | Synopsis |
---|---|
Package cssom provides functionality for CSS styling.
|
Package cssom provides functionality for CSS styling. |
douceuradapter
Package douceuradapter is a concrete implementation of interface cssom.StyleSheet.
|
Package douceuradapter is a concrete implementation of interface cssom.StyleSheet. |
style
Package style provides functionality for CSS styling properties.
|
Package style provides functionality for CSS styling properties. |
Package domdbg implements helpers to debug a DOM tree.
|
Package domdbg implements helpers to debug a DOM tree. |
Package styledtree is a straightforward default implementation of a styled document tree.
|
Package styledtree is a straightforward default implementation of a styled document tree. |
xpathadapter
Package xpathadapter implements an xpath.NodeNavigator.
|
Package xpathadapter implements an xpath.NodeNavigator. |
Package w3cdom defines an interface type for W3C Document Object Models.
|
Package w3cdom defines an interface type for W3C Document Object Models. |
Package xpath provides tree walking for the DOM with XPath syntax.
|
Package xpath provides tree walking for the DOM with XPath syntax. |