-
Notifications
You must be signed in to change notification settings - Fork 1
AstText (EN)
Text nodes that inherit the properties and methods of AstNode. Modeled after the Text class, the properties and methods are also very similar to the Text class.
✅ Available in the Mini and Browser versions.
✅ Expand
type: 'text'
Read-only. The text node type is always 'text'
. Conversely, type: 'text'
must correspond to a text node.
// type
var {firstChild} = Parser.parse('a');
assert.strictEqual(firstChild.type, 'text');
✅ Expand
type: string
The text content of the node, read-only.
// data
var {firstChild} = Parser.parse('a');
assert.strictEqual(firstChild.data, 'a');
Expand
type: number
The length of the text content, read-only.
// length
var {firstChild} = Parser.parse('a');
assert.strictEqual(firstChild.length, 1);
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild} = Parser.parse('{{[[<div');
assert.equal(firstChild, '{{[[<div');
assert.deepStrictEqual(firstChild.lint(), [
{
severity: 'error',
message: 'lonely "{"',
startLine: 0,
startCol: 0,
startIndex: 0,
endLine: 0,
endCol: 2,
endIndex: 2,
excerpt: '{{[[<div',
},
{
severity: 'error',
message: 'lonely "["',
startLine: 0,
startCol: 2,
startIndex: 2,
endLine: 0,
endCol: 4,
endIndex: 4,
excerpt: '{[[<div',
},
{
severity: 'warning',
message: 'lonely "<"',
startLine: 0,
startCol: 4,
startIndex: 4,
endLine: 0,
endCol: 8,
endIndex: 8,
excerpt: '[<div',
},
])
✅ Expand
param: string
String to replace
Replace the string.
// replaceData
var {firstChild} = Parser.parse('a');
firstChild.replaceData('b');
assert.equal(firstChild, 'b');
Expand
returns: this
Clone the node.
// cloneNode
var {firstChild} = Parser.parse('a');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Expand
param: string
String to append
Append the string to the end.
// appendData
var {firstChild} = Parser.parse('a');
firstChild.appendData('b');
assert.equal(firstChild, 'ab');
Expand
param: number
Starting position
param: number
Number of characters to delete
Delete part of the string.
// deleteData
var {firstChild} = Parser.parse('abc');
firstChild.deleteData(1, 1);
assert.equal(firstChild, 'ac');
Expand
param: number
Position to insert
param: string
String to insert
Insert a string.
// insertData
var {firstChild} = Parser.parse('ab');
firstChild.insertData(1, 'c');
assert.equal(firstChild, 'acb');
Expand
param: number
Starting position
param: number
Number of characters to extract
returns: string
Extract a substring.
// substringData
var {firstChild} = Parser.parse('abc');
assert.strictEqual(firstChild.substringData(1, 1), 'b');
Expand
param: number
Position to split
Split the text node into two parts.
// splitText
var {firstChild} = Parser.parse('ab');
firstChild.splitText(1);
assert.equal(firstChild, 'a');
assert.equal(firstChild.nextSibling, 'b');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext