Initialize a new ParsedTemplate instance. This constructor is not supposed to be used externally.
When name has inline \n characters or when fullName
does not contain name as a substring.
CAUTION: Pseudo-private property. Use getEndIndex to get this property's value.
The index up to, but not including, the end of the template in the wikitext out of which the template was parsed.
Note that this property is made private-like because it shouldn't be modified externally, but sometimes Wikitext.parseTemplates needs to modify this property, from outside this class.
CAUTION: Pseudo-private property. Use getStartIndex to get this property's value.
The index to the start of the template in the wikitext out of which the template was parsed.
Note that this property is made private-like because it shouldn't be modified externally, but sometimes Wikitext.parseTemplates needs to modify this property, from outside this class.
Readonly argsThe arguments of the template parsed as an array of objects.
Readonly cleanname formatted by mw.Title.newFromText.
Readonly fullReadonly fullFull string that fits into the first slot of the template (i.e. {{fullName}}). May be accompanied by additional
characters that are not relevant to the title of the page to be transcluded.
Protected Readonly hierarchyArgument hierarchies.
Readonly keysAn array of the names of the template arguments.
Readonly nameThe trimmed name passed to the constructor.
Readonly nestThe nest level of the template. If not nested by other templates, the value is 0.
Readonly originalThe original text of the template.
Readonly overriddenThe overridden arguments of the template stored as an array of objects.
Add new arguments to the Template instance. This method leaves a log when argument override takes place, which can be viewed by getOverriddenArgs.
An array of {name: string; value: string;} objects.
Delete template arguments.
Deleted arguments.
Get (a deep copy of) a template argument by an argument name.
Argument name.
Optional options: GetArgOptions & GetArgUniqueOptionsOptional search options.
null if no argument is found with the specified name.
Get the arguments of the template as an array of objects.
Whether to return a deep copy, defaulted to true. Otherwise, args is passed by reference
(not recommended).
Get _endIndex.
Get the name of the template.
Optional prop: "full" | "clean" | "fullclean"By default, returns the original, unformatted name passed to Template.constructor.
full is passed, returns fullName passed to Template.constructor
(same as name if none was passed).clean is passed, returns name that is formatted.fullclean is passed, returns name that is formatted and accompanied by redundancies
as in fullName.In specifying any of the above, the first letter is capitalized.
Note that if name is prefixed by Template:, the namespace prefix is truncated in prop=clean and prop=fullclean.
// name: Template:test
const template = new Template('Template:test');
console.log(template.getName()): // Template:test
console.log(template.getName('full')): // Template:test
console.log(template.getName('clean')): // Test
console.log(template.getName('fullclean')): // Test
For the clean names, namespace aliases are formatted to their canonical ones.
// name: project:test', fullName: '<!--change?-->project:test
const template = new Template('project:test', {fullName: '<!--change?-->project:test'});
console.log(template.getName()): // project:test
console.log(template.getName('full')): // <!--change?-->project:test
console.log(template.getName('clean')): // Wikipedia:Test
console.log(template.getName('fullclean')): // <!--change?-->Wikipedia:Test
Get a list of overridden template arguments as an array of objects. This method returns a deep copy, and modifying the return value does not modify the original array stored in the class.
Get _startIndex.
Check whether the Template instance has an argument with a certain name.
Name of the argument to search for.
Optional options: GetArgOptionsOptional search options.
A boolean value in accordance with whether there is a match.
Render the Template instance as wikitext.
Use render({nameprop: 'full', unformatted: 'both'}) for an output that is closest to the original configurations.
Optional options: RenderOptionsOptional object of rendering specifications
Find the original template in a wikitext and replace it with the (updated) template obtained by render. This method is supposed to be called on a wiktiext same as the one from which the ParsedTemplate instance was parsed and initialized.
Note that if this method is called recursively against an array of ParsedTemplate, the looped array needs to be
reversed so that the replacement takes place from the bottom of the wikitext. This is because the method reads the start
and end indexes of the original template before the replacement (unless useIndex is set
to false), and if the replacement is done in a top-down fashion, the indexes change and the subsequent replacements are
affected.
Wikitext in which to search for the original template.
Optional options: RenderOptions & ReplaceInOptionsOptional object to specify rendering and replacement options.
New wikitext with the original template replaced. (Could be the same as the input wikitext if the replacement didn't take place.)
Set (or update) arguments in(to) the Template instance. This method does not leave a log when argument override takes place.
Note: New arguments are simply newly added, just as when addArgs is used.
An array of {name: string; value: string;} objects.
Get class properties in a JSON format.
Stringify the Template instance. Same as render({nameprop: 'full', unformatted: 'both'}).
Static newError-proof constructor. This method is supposed to be used only by Wikitext.parseTemplates.
null if the constructor threw an error.
Generated using TypeDoc
Class used by Wikitext.parseTemplates.