-
Notifications
You must be signed in to change notification settings - Fork 2
AtomToken
bhsd edited this page Jun 26, 2024
·
2 revisions
AtomToken 继承了 Token 类的全部属性和方法,这里不再列出。
✅ 展开
type: string
节点类型。
// type
var {firstChild: {firstChild}} = Parser.parse('{{{arg}}}'),
lastChild, variant, from, to, previousSibling;
assert.equal(firstChild, 'arg');
assert.strictEqual(firstChild.type, 'arg-name');
({firstChild: {firstChild: {lastChild: {firstChild, lastChild}}}} =
Parser.parse('<p id=value>'));
assert.equal(firstChild, 'id');
assert.equal(lastChild, 'value');
assert.strictEqual(firstChild.type, 'attr-key');
assert.strictEqual(lastChild.type, 'attr-value');
({firstChild: {firstChild: {firstChild}, lastChild}} =
Parser.parse('-{R|from=>zh-cn:to}-'));
({childNodes: [from, variant, to]} = lastChild);
assert.equal(firstChild, 'R');
assert.equal(from, 'from');
assert.equal(variant, 'zh-cn');
assert.equal(to, 'to');
assert.strictEqual(firstChild.type, 'converter-flag');
assert.strictEqual(from.type, 'converter-rule-from');
assert.strictEqual(variant.type, 'converter-rule-variant');
assert.strictEqual(to.type, 'converter-rule-to');
({firstChild: {firstChild}} = Parser.parse('{{template}}'));
assert.equal(firstChild, 'template');
assert.strictEqual(firstChild.type, 'template-name');
({firstChild: {lastChild}} = Parser.parse('{{#invoke:module|function}}'));
({previousSibling} = lastChild);
assert.equal(lastChild, 'function');
assert.equal(previousSibling, 'module');
assert.strictEqual(lastChild.type, 'invoke-function');
assert.strictEqual(previousSibling.type, 'invoke-module');
({firstChild: {firstChild}} = Parser.parse('[[link]]'));
assert.equal(firstChild, 'link');
assert.strictEqual(firstChild.type, 'link-target');
firstChild.type = 'arg-name';
assert.strictEqual(firstChild.type, 'arg-name');
展开
returns: this
深拷贝节点。
// cloneNode (main)
var {firstChild: {firstChild}} = Parser.parse('{{{a}}}');
assert.equal(firstChild, 'a');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext