TranslateToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Table of Contents
<translate>
tags from Extension:Translate. This class inherits all the properties and methods of the TagPairToken class which are not repeated here.
✅ Available in the Mini and Browser versions.
🌐 Available in the Browser version.
Inherited properties from TagPairToken
✅ Expand
type: string
// type
var {firstChild} = Parser.parse('<translate></translate>');
assert.equal(firstChild, '<translate></translate>');
assert.strictEqual(firstChild.type, 'translate');
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse('<translate>a</translate>');
assert.equal(firstChild, '<translate>a</translate>');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
({firstChild} = Parser.parse('<translate nowrap>a</translate>'));
assert.equal(firstChild, '<translate nowrap>a</translate>');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Expand
param: string
Attribute name
returns: string | true
Get the value of the nowrap
attribute.
// getAttr (main)
var {firstChild} = Parser.parse('<translate nowrap></translate>');
assert.equal(firstChild, '<translate nowrap></translate>');
assert.strictEqual(firstChild.getAttr('nowrap'), true);
assert.strictEqual(firstChild.getAttr('x'), undefined);
Expand
param: string
Attribute name
returns: boolean
Whether the nowrap
attribute exists.
// hasAttr (main)
var {firstChild} = Parser.parse('<translate nowrap></translate>');
assert.equal(firstChild, '<translate nowrap></translate>');
assert.ok(firstChild.hasAttr('nowrap'));
assert.ok(!firstChild.hasAttr('x'));
🌐 Expand
returns: string
Output in HTML format.
// print
var {firstChild} = Parser.parse('<translate nowrap>\n</translate>');
assert.equal(firstChild, '<translate nowrap>\n</translate>');
assert.strictEqual(
firstChild.print(),
`<span class="wpb-ext"><translate<span class="wpb-ext-attrs"> <span class="wpb-ext-attr"><span class="wpb-attr-key">nowrap</span></span></span>><span class="wpb-ext-inner">
</span></translate></span>`,
);
Expand
param: string
Attribute name
Remove the nowrap
attribute.
// removeAttr (main)
var {firstChild} = Parser.parse('<translate nowrap></translate>');
assert.equal(firstChild, '<translate nowrap></translate>');
firstChild.removeAttr('nowrap');
assert.equal(firstChild, '<translate></translate>');
Expand
param: string | Record<string, boolean>
Attribute name or attributes
param: boolean
Attribute value
Set the nowrap
attribute.
// setAttr (main)
var {firstChild} = Parser.parse('<translate></translate>');
assert.equal(firstChild, '<translate></translate>');
firstChild.setAttr('nowrap', true);
assert.equal(firstChild, '<translate nowrap></translate>');
firstChild.setAttr({nowrap: false});
assert.equal(firstChild, '<translate></translate>');
Expand
param: string
Attribute name
Toggle the nowrap
attribute.
// toggleAttr (main)
var {firstChild} = Parser.parse('<translate nowrap></translate>');
assert.equal(firstChild, '<translate nowrap></translate>');
firstChild.toggleAttr('nowrap');
assert.equal(firstChild, '<translate></translate>');
Expand
returns: string
Convert to HTML.
// toHtml (main)
var {firstChild} = Parser.parse('<translate><!--T:1--> a</translate>');
assert.equal(firstChild, '<translate><!--T:1--> a</translate>');
assert.strictEqual(firstChild.toHtml(), 'a');