-
Notifications
You must be signed in to change notification settings - Fork 2
HeadingToken
bhsd edited this page Jun 26, 2024
·
17 revisions
章节标题。
✅ 展开
type: number
标题层级,只读。
// name
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
assert.strictEqual(firstChild.level, 2);
展开
type: string
内部文本。
// innerText (main)
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
assert.strictEqual(firstChild.innerText, 'a');
firstChild.innerText = 'b';
assert.equal(firstChild, '==b==');
✅ 展开
returns: LintError[]
报告潜在语法错误。
// lint
var header = Parser.parse(`<p
=a''==
>`).querySelector('heading');
assert.equal(header, "=a''==");
assert.deepStrictEqual(header.lint(), [
{
rule: 'h1',
severity: 'error',
message: '<h1>',
startLine: 1,
startCol: 1,
startIndex: 4,
endLine: 1,
endCol: 5,
endIndex: 8,
},
{
rule: 'unbalanced-header',
severity: 'error',
message: 'unbalanced "=" in a section header',
startLine: 1,
startCol: 1,
startIndex: 4,
endLine: 1,
endCol: 5,
endIndex: 8,
},
{
rule: 'parsing-order',
severity: 'error',
message: 'section header in a HTML tag',
startLine: 1,
startCol: 0,
startIndex: 3,
endLine: 1,
endCol: 6,
endIndex: 9,
},
{
rule: 'format-leakage',
severity: 'error',
message: 'unbalanced italic apostrophes in a section header',
startLine: 1,
startCol: 2,
startIndex: 5,
endLine: 1,
endCol: 4,
endIndex: 7,
},
]);
展开
returns: this
深拷贝节点。
// cloneNode (main)
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
展开
param: number
标题层级
设置标题层级。
// setLevel (main)
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
firstChild.setLevel(3);
assert.equal(firstChild, '===a===');
展开
加入的版本: 1.10.0
returns: string
转换为 HTML。
// toHtml (main)
var {firstChild} = Parser.parse("= '' a b '' =");
assert.strictEqual(
firstChild.toHtml(),
`<div class="mw-heading mw-heading1"><h1 id="a_b"><i> a b </i></h1></div>`,
);
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext