Documentation
¶
Overview ¶
Package dom holds a raw-preserving SVG document tree. Every node keeps the exact input bytes that produced it; serialization emits those bytes verbatim unless the node was modified. Untouched markup therefore round-trips byte-for-byte, which is what makes "when unsure, leave it unchanged" safe and the output deterministic.
Index ¶
- func Serialize(doc *Node) []byte
- type Attr
- type Kind
- type Node
- func (n *Node) AttrValue(name string) (string, bool)
- func (n *Node) CanonicalizeStartTag()
- func (n *Node) HasAttr(name string) bool
- func (n *Node) Raw() []byte
- func (n *Node) RemoveAttr(name string)
- func (n *Node) RemoveChild(c *Node)
- func (n *Node) Rename(name string)
- func (n *Node) ReplaceWithChildren()
- func (n *Node) SetAttr(name, value string)
- func (n *Node) SetText(s string)
- func (n *Node) Walk(fn func(*Node) bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attr ¶
type Attr struct {
// Name is the attribute name as written, including any namespace prefix.
Name string
// contains filtered or unexported fields
}
Attr is one attribute of an element. The raw form (leading whitespace, original quoting, undecoded entities) is kept so that untouched attributes serialize verbatim even when a sibling attribute changed.
type Node ¶
type Node struct {
Kind Kind
Name string // element or PI name as written, including prefix
Attrs []Attr
Children []*Node
Parent *Node
// SelfClosing records whether the element used <name/> form.
SelfClosing bool
// contains filtered or unexported fields
}
Node is a document, element, or leaf (text, comment, CDATA, doctype, PI).
func Parse ¶
Parse builds a document tree from svg. It fails on malformed markup (mismatched or unclosed tags, no root element) so the caller can fall back to the untouched input.
func (*Node) AttrValue ¶
AttrValue returns the decoded value of the named attribute. ok is false when the attribute is absent or its value is opaque.
func (*Node) CanonicalizeStartTag ¶ added in v0.2.0
func (n *Node) CanonicalizeStartTag()
CanonicalizeStartTag re-serializes the start tag with single-space attribute separation when the original spelling wastes bytes (editor indentation inside tags). Inter-attribute whitespace is not significant in XML, so the document is equivalent.
func (*Node) Raw ¶
Raw returns the verbatim input bytes of a leaf node (text, comment, CDATA, doctype, processing instruction). It is nil for elements and documents.
func (*Node) RemoveAttr ¶
RemoveAttr removes the named attribute if present.
func (*Node) RemoveChild ¶
RemoveChild removes c from n's children. Surrounding markup is unaffected.
func (*Node) ReplaceWithChildren ¶
func (n *Node) ReplaceWithChildren()
ReplaceWithChildren splices n's children into its parent in n's place, dropping n's own tags. Used to unwrap groups.
func (*Node) SetAttr ¶
SetAttr sets the named attribute, appending it when absent, and marks the element for canonical re-serialization of its start tag.