-
Notifications
You must be signed in to change notification settings - Fork 2
TrToken (EN)
bhsd edited this page Jul 23, 2024
·
10 revisions
Table row.
✅ Available in the Mini and Browser versions.
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var tr = Parser.parse('{|\n|-\na\n|}').querySelector('tr');
assert.equal(tr, '\n|-\na');
assert.deepStrictEqual(tr.lint(), [
{
rule: 'fostered-content',
severity: 'error',
message: 'content to be moved out from the table',
startLine: 2,
startCol: 0,
startIndex: 6,
endLine: 2,
endCol: 1,
endIndex: 7,
},
]);
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr');
assert.equal(tr, '\n|-\n|a');
assert.deepStrictEqual(tr.cloneNode(), tr);
Expand
returns: number
Get the number of columns.
// getColCount (main)
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr');
assert.equal(tr, '\n|-\n|a');
assert.strictEqual(tr.getColCount(), 1);
Expand
returns: this
Get the next row.
// getNextRow (main)
var [a, b] = Parser.parse('{|\n|-\n|a\n|-\n!b\n|}').querySelectorAll('tr');
assert.equal(a, '\n|-\n|a');
assert.equal(b, '\n|-\n!b');
assert.strictEqual(a.getNextRow(), b);
Expand
returns: this
Get the previous row.
// getPreviousRow (main)
var [a, b] = Parser.parse('{|\n|-\n|a\n|-\n!b\n|}').querySelectorAll('tr');
assert.equal(a, '\n|-\n|a');
assert.equal(b, '\n|-\n!b');
assert.strictEqual(b.getPreviousRow(), a);
Expand
param: number
Column index
returns: TdToken
Get the n
th column.
// getNthCol (main)
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr'),
{lastChild} = tr;
assert.equal(tr, '\n|-\n|a');
assert.deepStrictEqual(tr.getNthCol(0), lastChild);
Expand
param: string
Text content of the new cell
param: {column: number}
Coordinates of the new cell
param: string
Subtype of the new cell
param: Record<string, string | number>
Attributes of the new cell
returns: TdToken
Insert a new cell.
// insertTableCell (main)
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr');
assert.equal(tr, '\n|-\n|a');
tr.insertTableCell('b', {column: 1}, 'th', {rowspan: 2});
assert.equal(tr.toString(), '\n|-\n|a\n!rowspan="2"|b');
Expand
version added: 1.10.0
returns: string
Convert to HTML.
// toHtml (main)
var [caption, td, empty] = Parser
.parse('{|\n|-id=a\n|+a\n|-id=b\n|b\n|-id=c\n\n|}')
.querySelectorAll('tr');
assert.equal(caption, '\n|-id=a\n|+a');
assert.equal(td, '\n|-id=b\n|b');
assert.equal(empty, '\n|-id=c\n');
assert.strictEqual(caption.toHtml(), '\n<caption >a</caption>');
assert.strictEqual(td.toHtml(), '<tr id="b">\n<td >b\n</td></tr>');
assert.strictEqual(empty.toHtml(), '');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext