Skip to content

TrToken (EN)

bhsd edited this page Dec 18, 2023 · 10 revisions

Other Languages

Introduction

Table row.

✅ Available in the Mini and Browser versions.

Methods

lint

✅ 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(), [
	{
		severity: 'error',
		message: 'content to be moved out from the table',
		startLine: 2,
		startCol: 0,
		startIndex: 6,
		endLine: 2,
		endCol: 1,
		endIndex: 7,
		excerpt: 'a',
	},
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr');
assert.equal(tr, '\n|-\n|a');
assert.deepStrictEqual(tr.cloneNode(), tr);

getColCount

Expand

returns: number
Get the number of columns.

// getColCount
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr');
assert.equal(tr, '\n|-\n|a');
assert.strictEqual(tr.getColCount(), 1);

getNextRow

Expand

returns: this
Get the next row.

// getNextRow
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);

getPreviousRow

Expand

returns: this
Get the previous row.

// getPreviousRow
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);

getNthCol

Expand

param: number Column index
returns: TdToken
Get the nth column.

// getNthCol
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr'),
	{lastChild} = tr;
assert.equal(tr, '\n|-\n|a');
assert.deepStrictEqual(tr.getNthCol(0), lastChild);

insertTableCell

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
var tr = Parser.parse('{|\n|-\n|a\n|}').querySelector('tr'),
	{lastChild} = 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');
Clone this wiki locally