dom

package
v0.0.0-...-ae32867 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Status

Just started development, so nothing finished to be found here. Please be patient.

Overview

HTMLbook is the core DOM of our documents. Background for this decision can be found in this Conference Paper and an O'Reilly Radar Page.

From the O'Reilly page:

"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 the O'Reilly HTMLBook Github-page.

For another source thinking about HTML and book publishing, consider this blog entry by Adam Hyde.

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

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

View Source
const AttrNode = html.NodeType(77)

AttrNode is an additional node type, complementing those defined in standard-package html.

Variables

View Source
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.

View Source
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

func NodeAsTreeNode(domnode w3cdom.Node) (*tree.Node, bool)

NodeAsTreeNode returns the underlying tree.Node from a DOM node.

func T

func T() tracing.Trace

T will return a tracer. We are tracing to the EngineTracer

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) ChildNodes

func (a *W3CAttr) ChildNodes() w3cdom.NodeList

ChildNodes returns nil

func (*W3CAttr) Children

func (a *W3CAttr) Children() w3cdom.NodeList

Children returns nil

func (*W3CAttr) ComputedStyles

func (a *W3CAttr) ComputedStyles() w3cdom.ComputedStyles

ComputedStyles gets null-styles

func (*W3CAttr) FirstChild

func (a *W3CAttr) FirstChild() w3cdom.Node

FirstChild returns nil

func (*W3CAttr) HasAttributes

func (a *W3CAttr) HasAttributes() bool

HasAttributes returns false

func (*W3CAttr) HasChildNodes

func (a *W3CAttr) HasChildNodes() bool

HasChildNodes returns false

func (*W3CAttr) Key

func (a *W3CAttr) Key() string

Key is the name of an attribute.

func (*W3CAttr) Namespace

func (a *W3CAttr) Namespace() string

Namespace returns the namespace prefix of an attribute.

func (*W3CAttr) NextSibling

func (a *W3CAttr) NextSibling() w3cdom.Node

NextSibling returns nil

func (*W3CAttr) NodeName

func (a *W3CAttr) NodeName() string

NodeName for an attribute is the attribute key

func (*W3CAttr) NodeType

func (a *W3CAttr) NodeType() html.NodeType

NodeType returns type AttrNode

func (*W3CAttr) NodeValue

func (a *W3CAttr) NodeValue() string

NodeValue for an attribute is the attribute value

func (*W3CAttr) ParentNode

func (a *W3CAttr) ParentNode() w3cdom.Node

ParentNode returns nil

func (*W3CAttr) TextContent

func (a *W3CAttr) TextContent() (string, error)

TextContent returns an empty string

func (*W3CAttr) Value

func (a *W3CAttr) Value() string

Value is the string value of an attribute.

type W3CMap

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

A W3CMap represents a key-value map

func (*W3CMap) GetNamedItem

func (wm *W3CMap) GetNamedItem(key string) w3cdom.Attr

GetNamedItem returns the attribute with key key.

func (*W3CMap) Item

func (wm *W3CMap) Item(i int) w3cdom.Attr

Item returns the i.th item in a key-value map

func (*W3CMap) Length

func (wm *W3CMap) Length() int

Length returns the number of entries in a key-value map

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

func NodeFromTreeNode(tn *tree.Node) (*W3CNode, error)

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

func (w *W3CNode) ChildNodes() w3cdom.NodeList

ChildNodes read-only property returns a live NodeList of child nodes of the given element.

func (*W3CNode) Children

func (w *W3CNode) Children() w3cdom.NodeList

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

func (w *W3CNode) FirstChild() w3cdom.Node

FirstChild read-only property returns the node's first child in the tree, or nil if the node has no children.

func (*W3CNode) HTMLNode

func (w *W3CNode) HTMLNode() *html.Node

HTMLNode returns the HTML parse node this DOM node is derived from.

func (*W3CNode) HasAttributes

func (w *W3CNode) HasAttributes() bool

HasAttributes returns a boolean indicating whether the current element has any attributes or not.

func (*W3CNode) HasChildNodes

func (w *W3CNode) HasChildNodes() bool

HasChildNodes method returns a boolean value indicating whether the given Node has child nodes or not.

func (*W3CNode) IsDocument

func (w *W3CNode) IsDocument() bool

IsDocument returns wether this node is the document node of the styled tree.

func (*W3CNode) IsRoot

func (w *W3CNode) IsRoot() bool

IsRoot returns wether this node is the root node of the styled tree.

func (*W3CNode) NextSibling

func (w *W3CNode) NextSibling() w3cdom.Node

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

func (w *W3CNode) NodeName() string

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

func (w *W3CNode) NodeType() html.NodeType

NodeType returns the type of the underlying HTML node, something like html.ElementNode, html.TextNode, etc.

func (*W3CNode) NodeValue

func (w *W3CNode) NodeValue() string

NodeValue returns textual content for text/CData-Nodes, and an empty string for any other Node type.

func (*W3CNode) ParentNode

func (w *W3CNode) ParentNode() w3cdom.Node

ParentNode read-only property returns the parent of the specified node in the DOM tree.

func (*W3CNode) TextContent

func (w *W3CNode) TextContent() (string, error)

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: ... )".

func (*W3CNode) Walk

func (w *W3CNode) Walk() *tree.Walker

Walk creates a tree walker set up to traverse the DOM.

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.

Jump to

Keyboard shortcuts

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