Constructor
new Text(settings)
Example
new Text({ data: 'Hello World' })
Parameters:
Name | Type | Description |
---|---|---|
settings |
TextSettings | string | Custom settings applied to the Text, or the content of the Text. |
Extends
Members
data :string
Content of the Text
Type:
- string
index
- Source:
- Overrides:
Position of the current Node from its parent.
Example
node.index // returns the index of the node or -1
name :'#text'
Node name of the Text
Type:
- '#text'
next
Example
node.next // returns null
nextElement
- Source:
- Overrides:
Example
node.nextElement // returns an element or null
previous
- Source:
- Overrides:
Example
node.previous // returns a node or null
previousElement
- Source:
- Overrides:
Example
node.previousElement // returns an element or null
root
Top-most ancestor from the current Node.
Example
node.root // returns the top-most node or the current node itself
source :TextSource
Source mapping of the Text
Type:
sourceInnerHTML
Return the stringified innerHTML from the source input.
sourceOuterHTML
Return the stringified outerHTML from the source input.
textContent
Return the current Text as a String.
Example
text.textContent // returns ''
textContent
Define the current Text from a String.
Example
text.textContent = 'Hello World'
text.textContent // 'Hello World'
type :'text'
Type identifier of the Text
Type:
- 'text'
Methods
after(…nodes)
- Source:
- Overrides:
Example
node.after(new Text({ data: 'Hello World' }))
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes to be inserted after the current Node. |
append(…nodes)
- Source:
- Overrides:
Example
node.append(someOtherNode)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes to be inserted after the last child of the current Node. |
appendTo(parent)
- Source:
- Overrides:
Parameters:
Name | Type | Description |
---|---|---|
parent |
Container |
before(…nodes)
- Source:
- Overrides:
Insert Nodes or new Text Nodes before the Node if it has a parent, returning the current Node.
Example
node.before(new Text({ data: 'Hello World' })) // returns the current node
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes to be inserted before the current Node. |
clone(settings) → {Text}
Return a clone of the current Text.
Examples
text.clone()
Clone the current text with new source.
text.clone({ source: { input: 'modified source' } })
Parameters:
Name | Type | Description |
---|---|---|
settings |
Object | Custom settings applied to the cloned Text. |
Returns:
- Type
- Text
prepend(…nodes)
- Source:
- Overrides:
Example
node.prepend(someOtherNode)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes inserted before the first child of the current Node. |
remove()
- Source:
- Overrides:
Example
node.remove() // returns the current node
replaceWith(…nodes)
- Source:
- Overrides:
Example
node.replaceWith(someOtherNode) // returns the current node
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node |
<repeatable> |
Any nodes replacing the current Node. |
toJSON() → {string}
Return the current Text as a String.
Example
text.toJSON() // returns ''
Returns:
- Type
- string
toString() → {string}
Return the current Text as a String.
Example
text.toString() // returns ''
Returns:
- Type
- string
visit(result, overrideVisitorsopt) → {ResultPromise}
- Source:
- Overrides:
Transform the current Node and any descendants using visitors.
Examples
await node.visit(result)
await node.visit() // visit using the result of the current node
await node.visit(result, {
Element () {
// do something to an element
}
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
result |
Result | Result to be used by visitors. |
|
overrideVisitors |
Object |
<optional> |
Alternative visitors to be used in place of Result visitors. |
Returns:
- Type
- ResultPromise
warn(result, text, optsopt)
Add a warning from the current Node.
Examples
node.warn(result, 'Something went wrong')
node.warn(result, 'Something went wrong', {
node: someOtherNode,
plugin: someOtherPlugin
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
result |
Result | Result the warning is being added to. |
|
text |
string | Message being sent as the warning. |
|
opts |
Object |
<optional> |
Additional information about the warning. |