Help:ParserPower/Basic functions and tags

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. described below does and also performs the same trimming.

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  and   will keep three spaces on each side of. In the first case, it is because  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.

(Added in 1.0.)  works the same as , except that it wraps the content in a   block after unescaping so that the output is treated as plain text by the parser.

is effectively a shortcut combination of  and   in that it's like using   inside. 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.

is used to take a link and return the page name, unlinked. For example,  returns.

is used to take a link and return the link text, unlinked. For example,  returns.

, short for escape, is essentially the reverse of. If you call  on anything escaped with , 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  to call a template on a list of items, to write it without , you'd need to do something like this:

That prevents the example template from being called before the list is even processed. The  automatically replaces the escape sequences after processing, but it can be awkward to write patterns and other parameter values with escape sequences. Using, you can do this instead:

Unfortunately, due to limitations of the MediaWiki parser,  tags do not function correctly when inside other   tags. In other words,  will not work as expected

As a workaround, tags  through   have been provided should you need to nest   tags. Therefore, something like  does work as expected. The unexpected behavior only occurs when tags of the same name are nested inside each other.

(Added in 1.0), short for unescape if, is essentially ParserPower's version of ParserFunction's. The difference is that  automatically unescapes the output when it is finished.

It is used as follows:

If the given  value is not empty after trimming, then   will be unescaped and returned; otherwise,   will be unescaped and returned. Note that the value in  itself is not unescaped, but just parsed and trimmed normally, so even values such as   or   will be considered nonempty.

(Added in 1.0)  is used to return the first nonempty value among any number of given values. It is used as follows:

is first parsed and trimmed. If it isn't empty at that point, it is then unescaped and returned; otherwise,  is parsed and trimmed. If it isn't empty at that point, it is unescaped and returned; otherwise  is parsed and trimmed, and so on.

(Added in 1.0), short for unescape if equal, is essentially ParserPower's version of ParserFunction's. The difference is that  automatically unescapes the output when it is finished.

It is used as follows:

and  are parsed, trimmed, and unescaped. If they are exactly equal after this, then  will be unescaped and returned; otherwise,   will be unescaped and returned.

(Added in 1.0)  replaces a given token in the given pattern with the given value, returning and unescaping the result.

It is used as follows:

This is very similar to ParserFunction's  (if that's enabled), other than a different order of parameters and the unescaping performed by.

(Added in 1.0)  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:

Note that if both  and   are empty, this function returns nothing. That differs from, which would instead replace the token with an empty value and return whatever is left in.

(Added in 1.0)  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, but note that it has some differences beyond just unescaping output afterwards.

It is used as follows:

In this case, if  is equal to   after unescaping, then   is returned. Otherwise, it checks  and returns   if that matches. If not, it will return. Note that an arbitrary number of value-output pairs can be given. The, 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  escape sequence can be used to return an equal sign if needed.

also supports fall-through semantics, which work like this:

In this case, if  matches either   or ,   will be returned. For a match with,  , or  ,   will be returned.

(Added in 1.0)  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  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.