-
Notifications
You must be signed in to change notification settings - Fork 2
TableToken (EN)
bhsd edited this page Feb 12, 2024
·
13 revisions
Table of Contents
Table.
✅ Available in the Mini and Browser versions.
✅ Expand
type: boolean
Whether the table is closed.
// closed
var {firstChild} = Parser.parse('{|\n!a');
assert.equal(firstChild, '{|\n!a');
assert(!firstChild.closed);
firstChild.closed = true;
assert.equal(firstChild, '{|\n!a\n|}');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild} = Parser.parse('{|\na');
assert.equal(firstChild, '{|\na');
assert.deepStrictEqual(firstChild.lint(), [
{
rule: 'fostered-content',
severity: 'error',
message: 'content to be moved out from the table',
startLine: 1,
startCol: 0,
startIndex: 3,
endLine: 1,
endCol: 1,
endIndex: 4,
},
{
rule: 'unclosed-table',
severity: 'error',
message: 'unclosed table',
startLine: 0,
startCol: 0,
startIndex: 0,
endLine: 0,
endCol: 2,
endIndex: 2,
},
]);
✅ Expand
Close the table.
// close
var {firstChild} = Parser.parse('{|\n!a');
assert.equal(firstChild, '{|\n!a');
firstChild.close();
assert.equal(firstChild, '{|\n!a\n|}');
Expand
returns: this
Deep clone the node.
// cloneNode
var {firstChild} = Parser.parse('{|\n!a');
assert.equal(firstChild, '{|\n!a');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Expand
Escape table syntax.
// escape
var {firstChild} = Parser.parse('{|\n|-\n|a\n|}');
assert.equal(firstChild, '{|\n|-\n|a\n|}');
firstChild.escape();
assert.equal(firstChild, '{{{!}}\n{{!}}-\n{{!}}a\n{{!}}}');
Expand
returns: number
Get the number of rows.
// getRowCount
var {firstChild} = Parser.parse('{|\n|a\n|-\n|}');
assert.equal(firstChild, '{|\n|a\n|-\n|}');
assert.strictEqual(firstChild.getRowCount(), 1); // The first row can be the table itself. Empty rows are not counted.
Expand
returns: number
Get the number of columns. Only for TableToken
itself when used as a row.
// getColCount
var {firstChild} = Parser.parse('{|\n|a\n|}');
assert.equal(firstChild, '{|\n|a\n|}');
assert.strictEqual(firstChild.getColCount(), 1);
Expand
returns: TrToken
Get the next row (the row directly after the table itself).
// getNextRow
var {firstChild} = Parser.parse('{|\n|-\n|a\n|}'),
tr = firstChild.querySelector('tr');
assert.equal(firstChild, '{|\n|-\n|a\n|}');
assert.strictEqual(firstChild.getNextRow(), tr);
Expand
param: number
Row number
returns: TrToken
Get the n
th row.
// getNthRow
var {firstChild} = Parser.parse('{|\n!a\n|-\n|b\n|}'),
tr = firstChild.querySelector('tr');
assert.equal(firstChild, '{|\n!a\n|-\n|b\n|}');
assert.strictEqual(firstChild.getNthRow(0), firstChild);
assert.strictEqual(firstChild.getNthRow(1), tr);
Expand
param: number
Column number
returns: TdToken
Get the n
th column. Only for TableToken
itself when used as a row.
// getNthCol
var {firstChild} = Parser.parse('{|\n!a\n|}'),
td = firstChild.querySelector('td');
assert.equal(firstChild, '{|\n!a\n|}');
assert.strictEqual(firstChild.getNthCol(0), td);
Expand
returns: TdToken[]
Get all rows.
// getAllRows
var {firstChild} = Parser.parse('{|\n!a\n|-\n|b\n|}'),
tr = firstChild.querySelector('tr');
assert.equal(firstChild, '{|\n!a\n|-\n|b\n|}');
assert.deepStrictEqual(firstChild.getAllRows(), [firstChild, tr]);
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext