-
Notifications
You must be signed in to change notification settings - Fork 1
MagicLinkToken (EN)
bhsd edited this page Jul 4, 2024
·
15 revisions
Table of Contents
Free external link.
All of the following properties and methods are not available in the Mini and Browser versions.
✅ Expand
version added: 1.10.0
type: string
Link text, read-only.
// innerText
var {firstChild} = Parser.parse('ftp://a');
assert.strictEqual(firstChild.innerText, 'ftp://a');
✅ Expand
type: string
The external link.
// link
var {firstChild} = Parser.parse('ftp://a');
assert.strictEqual(firstChild.link, 'ftp://a');
// link (main)
var {firstChild} = Parser.parse('ftp://a');
firstChild.link = 'https://b';
assert.equal(firstChild, 'https://b');
Expand
type: string
Protocol of the external link.
// protocol (main)
var {firstChild} = Parser.parse('ftp://a');
assert.strictEqual(firstChild.protocol, 'ftp://');
firstChild.protocol = 'https://';
assert.equal(firstChild, 'https://a');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild} = Parser.parse('http://a。b');
assert.equal(firstChild, 'http://a。b');
assert.deepStrictEqual(firstChild.lint(), [
{
rule: 'unterminated-url',
severity: 'warning',
message: 'full-width punctuation in URL',
startLine: 0,
startCol: 0,
startIndex: 0,
endLine: 0,
endCol: 10,
endIndex: 10,
suggestions: [
{
desc: 'whitespace',
range: [8, 8],
text: ' ',
},
{
desc: 'escape',
range: [8, 9],
text: '%E3%80%82',
},
],
},
]);
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse('http://a');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Expand
returns: URL
Get the URL object.
// getUrl (main)
var {firstChild} = Parser.parse('http://a');
assert.deepStrictEqual(firstChild.getUrl(), new URL('http://a/'));
Expand
param: string | URL
URL, contains the protocol
Set the target of the external link.
// setTarget (main)
var {firstChild} = Parser.parse('http://a');
firstChild.setTarget('https://b');
assert.equal(firstChild, 'https://b');
Expand
returns: boolean
Whether it is a template or magic word parameter.
// isParamValue (main)
var link = Parser.parse('{{a|http://a}}').querySelector('free-ext-link');
assert.equal(link, 'http://a');
assert(link.isParamValue());
Expand
version added: 1.1.4
Escape =
.
// escape (main)
var {firstChild} = Parser.parse('http://a/b?c=');
assert.equal(firstChild, 'http://a/b?c=');
firstChild.escape();
assert.equal(firstChild, 'http://a/b?c{{=}}');
Expand
version added: 1.10.0
returns: string
Convert to HTML.
// toHtml (main)
var {firstChild} = Parser.parse('ftp://a');
assert.strictEqual(
firstChild.toHtml(),
'<a rel="nofollow" class="external free" href="ftp://a/">ftp://a</a>',
);
({firstChild} = Parser.parse('ISBN 1-2-3-4-5-6-7-8-9-0'));
assert.strictEqual(
firstChild.toHtml(),
`<a href="/wiki/Special%3ABookSources%2F1234567890">ISBN 1-2-3-4-5-6-7-8-9-0</a>`,
);
({firstChild} = Parser.parse('PMID 1'));
assert.strictEqual(
firstChild.toHtml(),
`<a rel="nofollow" class="external" href="https://pubmed.ncbi.nlm.nih.gov/1">PMID 1</a>`,
);
({firstChild} = Parser.parse('RFC 1'));
assert.strictEqual(
firstChild.toHtml(),
`<a rel="nofollow" class="external" href="https://tools.ietf.org/html/rfc1">RFC 1</a>`,
);
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext