-
Notifications
You must be signed in to change notification settings - Fork 1
TdToken (EN)
bhsd edited this page Jul 23, 2024
·
13 revisions
Table of Contents
Table cell.
✅ Available in the Mini and Browser versions.
✅ 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|');
✅ 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"|');
✅ 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"|');
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');
✅ 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',
},
},
]);
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());
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);
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 b</caption>');
assert.strictEqual(th.toHtml(), '\n<th id="c">c\n</th>');
assert.strictEqual(td.toHtml(), '\n<td id="d">d\n</td>');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext