Skip to main content

HTMLSimpleDOM

Import :

const HTMLSimpleDOM = brackets.getModule("language/HTMLSimpleDOM")

SimpleNode

Kind: global class

new SimpleNode(properties)

A SimpleNode represents one node in a SimpleDOM tree. Each node can have any set of properties on it, though there are a couple of assumptions made. Elements will have children and attributes properties. Text nodes will have a content property. All Elements will have a tagID and text nodes can have one.

ParamTypeDescription
propertiesObjectthe properties provided will be set on the new object.

simpleNode.update()

Updates signatures used to optimize the number of comparisons done during diffing. This is important to call if you change:

  • children
  • child node attributes
  • text content of a text node
  • child node text

Kind: instance method of SimpleNode

simpleNode.updateAttributeSignature()

Updates the signature of this node's attributes. Call this after making attribute changes.

Kind: instance method of SimpleNode

simpleNode.isElement() ⇒ bool

Is this node an element node?

Kind: instance method of SimpleNode
Returns: bool - true if it is an element

simpleNode.isText() ⇒ bool

Is this node a text node?

Kind: instance method of SimpleNode
Returns: bool - true if it is text

Builder

Kind: global class

new Builder(text, startOffset, startOffsetPos)

A Builder creates a SimpleDOM tree of SimpleNode objects representing the "important" contents of an HTML document. It does not include things like comments. The nodes include information about their position in the text provided.

ParamTypeDescription
textstringThe text to parse
startOffsetintstarting offset in the text
startOffsetPosObjectline/ch position in the text

builder.getID ⇒ int

Returns the best tag ID for the new tag object given. The default implementation just calls getNewID and returns a unique ID.

Kind: instance property of Builder
Returns: int - unique tag ID

ParamTypeDescription
newTagObjecttag object to potentially inspect to choose an ID

builder.build(strict, markCache) ⇒ SimpleNode

Builds the SimpleDOM.

Kind: instance method of Builder
Returns: SimpleNode - root of tree or null if parsing failed

ParamTypeDescription
strictboolif errors are detected, halt and return null
markCacheObjecta cache that can be used in ID generation (is passed to getID)

builder.getNewID() ⇒ int

Returns a new tag ID.

Kind: instance method of Builder
Returns: int - unique tag ID

build(text, strict) ⇒ SimpleNode

Builds a SimpleDOM from the text provided. If strict mode is true, parsing will halt as soon as any error is seen and null will be returned.

Kind: global function
Returns: SimpleNode - root of tree or null if strict failed

ParamTypeDescription
textstringText of document to parse
strictboolTrue for strict parsing