|
#trim
[]
#trim
is a simple function that just trims whitespace, such as spaces and newlines, from the beginning and end of the given value.
Important note: this function does not recognize ParserPower escape sequences. #uesc
described below does and also performs the same trimming.
#uesc
[]
#uesc
is short for unescape. It replaces the ParserPower escape sequences inside it with the characters they represent. It also does this after trimming, allowing for leading and trailing whitespace to be protected from trimming. For example, both {{#uesc:\0 word \0}}
and {{#uesc:\_ word \_}}
will keep three spaces on each side of word
. In the first case, it is because \0
is replaced with nothing, but protects the three nearby spaces from being stripped before it's replaced. In the second case, it is because \_
is replaced with a space and it protects the two nearby spaces from being stripped before it's replaced.
#uescnowiki
[]
(Added in 1.0.) #uescnowiki
works the same as #uesc
, except that it wraps the content in a <nowiki>
block after unescaping so that the output is treated as plain text by the parser.
#trimuesc
[]
#trimuesc
is effectively a shortcut combination of #trim
and #uesc
in that it's like using #uesc
inside #trim
. It recognizes ParserPower escape sequences, but it trims leading and trailing whitespace after the escape sequences are replaced so that leading and trailing whitespace are not protected.
<linkpage>
[]
<linkpage>
is used to take a link and return the page name, unlinked. For example, <linkpage>[[Help:Main page|Home]]</linkpage>
returns Main page
.
<linktext>
[]
<linktext>
is used to take a link and return the link text, unlinked. For example, <linktext>[[Help:Main page|Home]]</linktext>
returns Home
.
<esc>
[]
<esc>
, short for escape, is essentially the reverse of #uesc
. If you call #uesc
on anything escaped with <esc>
, the original content is returned. It works as follows:
\\
is replaced with\\\\
.- Any other ParserPower escape sequence already there has an extra backslash added to the front.
- For all other characters, any character that has a ParserPower escape sequence is replaced with that sequence.
This can be very useful in other ParserPower functions where parameters support the escape sequences. For example, if you use #lstmap
to call a template on a list of items, to write it without <esc>
, you'd need to do something like this:
{{#lstmap:{{{1|}}}|,|@@@@|{\{example\!param=@@@@}\}|}}
That prevents the example template from being called before the list is even processed. The #lstmap
automatically replaces the escape sequences after processing, but it can be awkward to write patterns and other parameter values with escape sequences. Using <esc>
, you can do this instead:
{{#lstmap:{{{1|}}}|,|@@@@|<esc>{{example|param=@@@@}}</esc>|}}
Unfortunately, due to limitations of the MediaWiki parser, <esc>
tags do not function correctly when inside other <esc>
tags. In other words, <esc>{{example|param=<esc>value</esc>}}</esc>
will not work as expected
As a workaround, tags <esc1>
through <esc9>
have been provided should you need to nest <esc>
tags. Therefore, something like <esc>{{example|param=<esc1>value</esc1>}}</esc>
does work as expected. The unexpected behavior only occurs when tags of the same name are nested inside each other.
#ueif
[]
(Added in 1.0) #ueif
, short for unescape if, is essentially ParserPower's version of ParserFunction's #if
. The difference is that #ueif
automatically unescapes the output when it is finished.
It is used as follows:
{{#ueif:condition|output1|output2}}
If the given condition
value is not empty after trimming, then output1
will be unescaped and returned; otherwise, output2
will be unescaped and returned. Note that the value in condition
itself is not unescaped, but just parsed and trimmed normally, so even values such as \0
or \_
will be considered nonempty.
#or
[]
(Added in 1.0) #or
is used to return the first nonempty value among any number of given values. It is used as follows:
{{#or:output1|output2|output3|...|outputn}}
output1
is first parsed and trimmed. If it isn't empty at that point, it is then unescaped and returned; otherwise, output2
is parsed and trimmed. If it isn't empty at that point, it is unescaped and returned; otherwise output3
is parsed and trimmed, and so on.
#ueifeq
[]
(Added in 1.0) #ueifeq
, short for unescape if equal, is essentially ParserPower's version of ParserFunction's #ifeq
. The difference is that #ueifeq
automatically unescapes the output when it is finished.
It is used as follows:
{{#ueifeq:lvalue|rvalue|output1|output2}}
lvalue
and rvalue
are parsed, trimmed, and unescaped. If they are exactly equal after this, then output1
will be unescaped and returned; otherwise, output2
will be unescaped and returned.
#token
[]
(Added in 1.0) #token
replaces a given token in the given pattern with the given value, returning and unescaping the result.
It is used as follows:
{{#token:value|token|pattern}}
This is very similar to ParserFunction's #replace
(if that's enabled), other than a different order of parameters and the unescaping performed by #token
.
#tokenif
[]
(Added in 1.0) #tokenif
replaces a given token in the given pattern with the given value, returning and unescaping the result, unless the given value is empty, in which case the given default is returned.
It is used as follows:
{{#tokenif:value|token|pattern|default}}
Note that if both value
and default
are empty, this function returns nothing. That differs from #token
, which would instead replace the token with an empty value and return whatever is left in pattern
.
#ueswitch
[]
(Added in 1.0) #ueswitch
takes a value, compares it a given list of values, and returns output associated with the matching value or default output if it matches nothing. This is similar to ParserFunction's #switch
, but note that it has some differences beyond just unescaping output afterwards.
It is used as follows:
{{#ueswitch:value |value1=output1 |value2=output2 |default output }}
In this case, if value
is equal to value1
after unescaping, then output1
is returned. Otherwise, it checks value2
and returns output2
if that matches. If not, it will return default output
. Note that an arbitrary number of value-output pairs can be given. The default output
, if given, must be the last in the list. It cannot have an equal sign in it because it will be interpreted as a value-output pair if so, but the \e
escape sequence can be used to return an equal sign if needed.
#ueswitch
also supports fall-through semantics, which work like this:
{{#ueswitch:value |value1 |value2=output1 |value3 |value4 |value5=output2 }}
In this case, if value
matches either value1
or value2
, output1
will be returned. For a match with value3
, value4
, or value5
, output2
will be returned.
#follow
[]
(Added in 1.0) #follow
will check to see if the given page name is a redirect. If so, it will return the name of the page it redirects to. Otherwise, it simply returns the same page name it was given.
Be warned that there are caching issues with the use of this function. If is used on one page and the page it refers to is changed to redirect to another page, deleted, or is edited to no longer be a redirect, the page using #follow
will not update until the page is saved or until another event causes the page to be regenerated. The function is mostly intended for use with features of extensions like Cargo, which have similar caching issues of their own, and hence this function's caching limitations do not add new difficulties.
|