-
Notifications
You must be signed in to change notification settings - Fork 1
AttributeToken (EN)
bhsd edited this page Feb 20, 2024
·
13 revisions
Table of Contents
A single attribute of extension tags, HTML tags and tables.
✅ Available in the Mini and Browser versions.
✅ Expand
type: string
The name of the attribute in lowercase, read-only.
// name
var attr = Parser.parse('<REF name=a/>').querySelector('ext-attr');
assert.equal(attr, 'name=a');
assert.strictEqual(attr.name, 'name');
✅ Expand
type: string
The name of the tag in lowercase, read-only.
// tag
var attr = Parser.parse('<REF name=a/>').querySelector('ext-attr');
assert.equal(attr, 'name=a');
assert.strictEqual(attr.tag, 'ref');
✅ Expand
type: boolean
Whether the quotes are matched.
// balanced
var attr = Parser.parse('<p id="a>').querySelector('html-attr');
assert.equal(attr, 'id="a');
assert(!attr.balanced);
attr.balanced = true;
assert.equal(attr, 'id="a"');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var [lang, tabindex, align, style] = Parser.parse('<p xml:lang=zh tabindex=1 align=center style="filter:blur(5px)>')
.querySelectorAll('html-attr');
assert.equal(lang, 'xml:lang=zh');
assert.equal(tabindex, 'tabindex=1');
assert.equal(align, 'align=center');
assert.equal(style, 'style="filter:blur(5px)');
assert.deepStrictEqual(lang.lint(), [
{
rule: 'illegal-attr',
severity: 'error',
message: 'illegal attribute name',
startLine: 0,
startCol: 3,
startIndex: 3,
endLine: 0,
endCol: 11,
endIndex: 11,
},
]);
assert.deepStrictEqual(tabindex.lint(), [
{
rule: 'illegal-attr',
severity: 'error',
message: 'nonzero tabindex',
startLine: 0,
startCol: 24,
startIndex: 24,
endLine: 0,
endCol: 25,
endIndex: 25,
suggestions: [
{
desc: 'remove',
range: [15, 25],
text: '',
},
{
desc: '0 tabindex',
range: [24, 25],
text: '0',
}
],
},
]);
assert.deepStrictEqual(align.lint(), [
{
rule: 'obsolete-attr',
severity: 'warning',
message: 'obsolete attribute',
startLine: 0,
startCol: 26,
startIndex: 26,
endLine: 0,
endCol: 31,
endIndex: 31,
},
]);
assert.deepStrictEqual(style.lint(), [
{
rule: 'unclosed-quote',
severity: 'warning',
message: 'unclosed quotes',
startLine: 0,
startCol: 45,
startIndex: 45,
endLine: 0,
endCol: 62,
endIndex: 62,
fix: {
range: [62, 62],
text: '"',
},
},
{
rule: 'insecure-style',
severity: 'error',
message: 'insecure style',
startLine: 0,
startCol: 46,
startIndex: 46,
endLine: 0,
endCol: 62,
endIndex: 62,
},
]);
✅ Expand
returns: string | true
Get the value of the attribute.
// getValue
var attr = Parser.parse('<p id=a>').querySelector('html-attr');
assert.equal(attr, 'id=a');
assert.strictEqual(attr.getValue(), 'a');
Expand
returns: this
Deep clone the node.
// cloneNode
var [ext, html, table] = Parser.parse('<ref name=a/><p id=b>\n{|id=c\n|}')
.querySelectorAll('ext-attr, html-attr, table-attr');
assert.equal(ext, 'name=a');
assert.equal(html, 'id=b');
assert.equal(table, 'id=c');
assert.deepStrictEqual(ext.cloneNode(), ext);
assert.deepStrictEqual(html.cloneNode(), html);
assert.deepStrictEqual(table.cloneNode(), table);
Expand
Escape equal signs. Used inside templates.
// escape
var attr = Parser.parse('<p id=a>').querySelector('html-attr');
assert.equal(attr, 'id=a');
attr.escape();
assert.equal(attr, 'id{{=}}a');
Expand
Close the quotes.
// close
var attr = Parser.parse('<p id="a>').querySelector('html-attr');
assert.equal(attr, 'id="a');
attr.close();
assert.equal(attr, 'id="a"');
Expand
param: string | boolean
Attribute value
Set the value of the attribute.
// setValue
var attr = Parser.parse('<p id=a>').querySelector('html-attr');
assert.equal(attr, 'id=a');
attr.setValue('b');
assert.equal(attr, 'id="b"');
attr.setValue(false);
assert.strictEqual(attr.parentNode, undefined);
Expand
param: string
Attribute name
Rename the attribute.
// rename
var attr = Parser.parse('<p id=a>').querySelector('html-attr');
assert.equal(attr, 'id=a');
attr.rename('class');
assert.equal(attr, 'class=a');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext