Skip to content

TdToken (EN)

bhsd edited this page Jul 23, 2024 · 13 revisions
Table of Contents

Other Languages

Introduction

Table cell.

✅ Available in the Mini and Browser versions.

Properties

subtype

✅ Expand

type: 'td' | 'th' | 'caption'
Subtype of the cell.

// subtype
var [caption, th, td] = Parser.parse('{|\n|+\n!\n|\n|}').querySelectorAll('td');
assert.equal(caption, '\n|+');
assert.equal(th, '\n!');
assert.equal(td, '\n|');
assert.strictEqual(caption.subtype, 'caption');
assert.strictEqual(th.subtype, 'th');
assert.strictEqual(td.subtype, 'td');
// subtype (main)
var [, th] = Parser.parse('{|\n|+\n!\n|\n|}').querySelectorAll('td');
th.subtype = 'td';
assert.equal(th, '\n|');

rowspan

✅ Expand

type: number

// rowspan
var td = Parser.parse('{|\n|\n|}').querySelector('td');
assert.equal(td, '\n|');
assert.strictEqual(td.rowspan, 1);
// rowspan (main)
var td = Parser.parse('{|\n|\n|}').querySelector('td');
td.rowspan = 2;
assert.equal(td, '\n|rowspan="2"|');

colspan

✅ Expand

type: number

// colspan
var td = Parser.parse('{|\n|\n|}').querySelector('td');
assert.equal(td, '\n|');
assert.strictEqual(td.colspan, 1);
// colspan (main)
var td = Parser.parse('{|\n|\n|}').querySelector('td');
td.colspan = 2;
assert.equal(td, '\n|colspan="2"|');

innerText

Expand

type: string
Text content of the cell.

// innerText (main)
var td = Parser.parse('{|\n|\n|}').querySelector('td');
assert.equal(td, '\n|');
assert.strictEqual(td.innerText, '');
td.innerText = 'a';
assert.equal(td, '\n|a');

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var td = Parser.parse('{|\n|\na||b\n|}').querySelector('td');
assert.equal(td, '\n|\na||b');
assert.deepEqual(td.lint(), [
	{
		rule: 'pipe-like',
		severity: 'error',
		message: 'additional "|" in a table cell',
		startLine: 1,
		startCol: 1,
		startIndex: 4,
		endLine: 2,
		endCol: 4,
		endIndex: 9,
		fix: {
			range: [4, 9],
			text: '\na\n|b',
		},
	},
]);

isIndependent

Expand

returns: boolean
Whether the cell is at the start of a line.

// isIndependent (main)
var [a, b] = Parser.parse('{|\n!a||b\n|}').querySelectorAll('td');
assert.equal(a, '\n!a');
assert.equal(b, '||b');
assert(a.isIndependent());
assert(!b.isIndependent());

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var th = Parser.parse('{|\n!a\n|}').querySelector('td');
assert.equal(th, '\n!a');
assert.deepStrictEqual(th.cloneNode(), th);

toHtml

Expand

version added: 1.10.0

returns: string
Convert to HTML.

// toHtml (main)
var [caption, th, td] = Parser.parse('{|\n|+id=a|a\nb\n!id=c|c\n|id=d|d\n|}')
	.querySelectorAll('td');
assert.equal(caption, '\n|+id=a|a\nb');
assert.equal(th, '\n!id=c|c');
assert.equal(td, '\n|id=d|d');
assert.strictEqual(caption.toHtml(), '\n<caption id="a">a&#10;b</caption>');
assert.strictEqual(th.toHtml(), '\n<th id="c">c\n</th>');
assert.strictEqual(td.toHtml(), '\n<td id="d">d\n</td>');
Clone this wiki locally