Represents a line of text in a Tree
.
For example if we have a Tree representing a Markdown document, then each line in the document is represented by a node. The nodes can have different types, such as 'heading', 'body', etc. Nodes form a tree structure. For example a node of type 'heading' contain "body" nodes as children.
To create a new node use Tree#createNode
.
- Tutorials:
Members
- tree :Tree
- id :String
- parent :Node
- firstChild :Node
- lastChild :Node
- previousSibling :Node
- nextSibling :Node
Methods
Type
- type() → String
- setType(type) → String
- typeIndentLevel() → Number
- setTypeIndentLevel(typeIndentLevel) → Number
- setBranchTypeIndentLevel(typeIndentLevel)
Mode
- mode() → String
- setMode(mode) → String
- modeContext() → String
Tags
- tags() → Object
- tag(tagName) → String
- hasTag(tagName) → Boolean
- addTag(tagName, tagValue)
- removeTag(tagName)
Text
Line
- line() → String
- lineInRange(location, length) → String
- setLine(line)
- replaceLineInRange(insertedText, location, length)
- lineNumber() → Number
- lineTextStart() → Number
- lineAttributedString() → AttributedString
Children
- hasChildren() → Boolean
- children() → Array.<Node>
- childAtIndex(index) → Node
- indexToSelf(onlyCountSiblingsWithSameType) → Number
- insertChildBefore(aChild, referenceSibling)
- appendChild(aChild)
- removeChild(aChild)
- removeFromParent()
Traversal
- isRoot() → Boolean
- isAncestorOfSelf(node) → Boolean
- previousBranch() → Node
- nextBranch() → Node
- descendants() → Array.<Node>
- lastDescendant() → Node
- lastDescendantOrSelf() → Node
- previousLineNode() → Node
- nextLineNode() → Node
- evaluateNodePath(nodePath) → Array.<Node>
- branchToText() → String
- <static> commonAncestorsForNodes(nodes) → NodeSet
- <static> ancestorsForNodes(nodes) → NodeSet
Member Details
-
tree :module:ft/core/tree.Tree
-
Owning Tree.
Type:
-
id :String
-
Unique ID within Tree.
Type:
- String
-
parent :module:ft/core/node.Node
-
Parent node, or null.
Type:
-
firstChild :module:ft/core/node.Node
-
First child node, or null.
Type:
-
lastChild :module:ft/core/node.Node
-
Last child node, or null.
Type:
-
previousSibling :module:ft/core/node.Node
-
Previous siblingnode, or null.
Type:
-
nextSibling :module:ft/core/node.Node
-
Next sibling node, or null.
Type:
Method Details
-
type() → {String}
-
Node "type" determined by classification process. For example in a Markdown document a nodes' type might be "heading" or "body".
Returns:
- Type
- String
-
setType(type) → {String}
-
Set new node type. Updates the node text content to match formatting of new type. For example if changing to "heading" in a Markdown document a "#" might be added to start of line. Preserves any trailing tags. Does not preserve type indent level.
Parameters:
Name Type Description type
String Returns:
- Type
- String
-
typeIndentLevel() → {Number}
-
The type-specific indent level of this node. For example a "heading" node will have an indent level from 1 to 6.
Returns:
- Type
- Number
-
setTypeIndentLevel(typeIndentLevel) → {Number}
-
Set type indent level for this node. For example, in a Markdown document, if you set a "heading" node to have a level of 2 then the line text will be adjusted so that it start with "##".
Parameters:
Name Type Description typeIndentLevel
Number New level requested.
Returns:
- Actual type level set, may be different than asked for level if asked for level isn't allowed. For example "heading" type levels stop at level 6.
- Type
- Number
-
setBranchTypeIndentLevel(typeIndentLevel)
-
Set type indent level of this node and also shift descendant node levels as needed. For example if this node is a level 1 "heading" node with a level 2 "heading" as a child, then setting this node to level 2 will adjust the child to be at level 3.
Parameters:
Name Type Description typeIndentLevel
Number New level requested.
-
mode() → {String}
-
The mode declared by this node, may be undefined. Only useful in Taxonomies that support modes.
Returns:
- Type
- String
-
setMode(mode) → {String}
-
Set the mode associated with this node. Only useful in Taxonomies that support modes.
Parameters:
Name Type Description mode
String New mode requested.
Returns:
- Actual mode applied.
- Type
- String
-
modeContext() → {String}
-
The mode affecting this node. For example if a "heading" node declares a mode, then all nodes contained by that heading will have that mode as their mode context. Only useful in Taxonomies that support modes.
Returns:
- Type
- String
-
tags() → {Object}
-
Readonly Object of tags associated with this node. Properties in returned object are tag names, property values are the tag values. Use
addTag
andremoveTag
to change tags.Returns:
- Type
- Object
-
tag(tagName) → {String}
-
Returns value of tag. If value is the empty string then the tag exists in this node, but has no associated value. If value is
undefined
then tag doesn't exist in this node.Parameters:
Name Type Description tagName
String Returns:
- Type
- String
-
hasTag(tagName) → {Boolean}
-
Return true of this node has the given tag.
Parameters:
Name Type Description tagName
String Returns:
- Type
- Boolean
-
addTag(tagName, tagValue)
-
Add a tag and optional tag value to this node.
Parameters:
Name Type Argument Description tagName
String tagValue
String <optional>
-
removeTag(tagName)
-
Remove a tag from this node.
Parameters:
Name Type Description tagName
String -
text() → {String}
-
Node's line of text minus leading and trailing syntax. Value depends on Taxonomy used to classify nodes. For example the
text
value of a heading in a markdown document will strip off the leading #'s.Returns:
- Type
- String
-
setText(text) → {String}
-
Replace node's text with new text. For example if you set the text of a heading in a markdown document the heading's leading # will be left in place.
Parameters:
Name Type Description text
String Returns:
- Type
- String
-
line() → {String}
-
Entire line of text represented by node. Does not including line break.
Returns:
- Type
- String
-
lineInRange(location, length) → {String}
-
Return substring of nodes line of text.
Parameters:
Name Type Description location
Number Relative to line start.
length
Number Length of text to extract.
Returns:
- Type
- String
-
setLine(line)
-
Replace represented line of text with a new line of text.
Parameters:
Name Type Description line
String -
replaceLineInRange(insertedText, location, length)
-
Replace a range of text in this node's line with new text.
Parameters:
Name Type Description insertedText
String Text to insert, should not include line break.
location
Number Location, relative to start of line, to start replacing.
length
Number Length of line region to replace.
-
lineNumber() → {Number}
-
Zero-based line number of this node in containing
Tree
.Returns:
- Type
- Number
-
lineTextStart() → {Number}
-
Text offset position of the start of this node's line in containing
Tree
.Returns:
- Type
- Number
-
lineAttributedString() → {AttributedString}
-
Return AttributedString for this node. The line of text represented by this line together with associated attribute ranges.
Returns:
- Type
- AttributedString
-
hasChildren() → {Boolean}
-
Return true if this node has child nodes.
Returns:
- Type
- Boolean
-
children() → {Array.<module:ft/core/node.Node>}
-
Return this node's children.
Returns:
- Type
- Array.<module:ft/core/node.Node>
-
childAtIndex(index) → {module:ft/core/node.Node}
-
Return this node's child at the given index
Parameters:
Name Type Description index
Number Returns:
-
indexToSelf(onlyCountSiblingsWithSameType) → {Number}
-
Return this node's position relative to its siblings.
Parameters:
Name Type Argument Description onlyCountSiblingsWithSameType
Boolean <optional>
Returns:
- Type
- Number
-
insertChildBefore(aChild, referenceSibling)
-
Insert a child node, inserting before the provided reference sibling. Depending on the types involved this may update the child's text content. For example if you add one heading to another, then the added becomes a level 2 heading and an extra
#
is added to the childs text.You can temporarily create invalid structures such as adding a heading to be a child of a body element. But if this happens the tree structure will soon be shuffled by the Classification process to make it valid.
Parameters:
Name Type Description aChild
module:ft/core/node.Node New child to add.
referenceSibling
module:ft/core/node.Node Sibling to insert before.
-
appendChild(aChild)
-
Append a new child node.
Parameters:
Name Type Description aChild
module:ft/core/node.Node Child to append.
-
removeChild(aChild)
-
Remove a child from this node.
Parameters:
Name Type Description aChild
module:ft/core/node.Node Child to remove.
-
removeFromParent()
-
Remove this node from it's parent.
-
isRoot() → {Boolean}
-
Each tree has a special "root" node that's the ancestor of all other nodes in the tree. It's special because unlike all other nodes the root node doesn't represent a line of text. You shouldn't try to modify the root node, it's just an implentation detail to make the tree structure work out.
Returns:
- True if this is the root node.
- Type
- Boolean
-
isAncestorOfSelf(node) → {Boolean}
-
Return true if given node is an ancestor of this node.
Parameters:
Name Type Description node
module:ft/core/node.Node Posible ancestor node.
Returns:
- Type
- Boolean
-
previousBranch() → {module:ft/core/node.Node}
-
Returns the previous branch in the node tree. Previous node before all descendants of this node's previous sibling.
Returns:
-
nextBranch() → {module:ft/core/node.Node}
-
Returns the next branch in node tree. Next node after all descendants of this node.
Returns:
-
descendants() → {Array.<module:ft/core/node.Node>}
-
Return all nodes descending from this node. This node's children, children's children, and so on.
Returns:
- Type
- Array.<module:ft/core/node.Node>
-
lastDescendant() → {module:ft/core/node.Node}
-
Return the last descendant of this node.
Returns:
-
lastDescendantOrSelf() → {module:ft/core/node.Node}
-
Return this node's last descendant, or if this node has no children then return this node.
Returns:
-
previousLineNode() → {module:ft/core/node.Node}
-
Return the node representing the previous line of text.
Returns:
-
nextLineNode() → {module:ft/core/node.Node}
-
Return the node representing the next line of text.
Returns:
-
evaluateNodePath(nodePath) → {Array.<module:ft/core/node.Node>}
-
Evaluate the node path starting with this node and return all matches.
Parameters:
Name Type Description nodePath
String Node path
- Tutorials:
-
- Tutorial: Node Paths
Returns:
- Type
- Array.<module:ft/core/node.Node>
-
branchToText() → {String}
-
Returns the text represented by this node and all of its decendants.
Returns:
- Type
- String
-
<static> commonAncestorsForNodes(nodes) → {module:ft/core/nodeset.NodeSet}
-
Return the common ancestors from the given nodes.
Parameters:
Name Type Description nodes
Array.<module:ft/core/node.Node> Returns:
-
<static> ancestorsForNodes(nodes) → {module:ft/core/nodeset.NodeSet}
-
Returns all ancestors of the given nodes.
Parameters:
Name Type Description nodes
Array.<module:ft/core/node.Node> Returns: