TrToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Table row. This class inherits all the properties and methods of the Token class which are not repeated here.
✅ 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: "warning",
message: "content to be moved outside 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 nth 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, '\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(), "");