Template:Escape
Uses Lua: |
Usage
While primarily intended for use by other Lua modules, it can provide an alternative to multiple <nowiki>...</nowiki>
tags when part of the desired output should be executed.
For example, Tdemo normally requires the demonstrated template to be wrapped in <nowiki>...</nowiki>
. However, you may want part of the value to be shown in the 'pre' tag to be processed before it reaches Tdemo, such as in the example below where the result of {{#invoke:Escape/testcases|test_string2}}
is shown inside the <pre>...</pre>
tags.
Code | Result |
---|---|
{{demo
|<!--not escaped: -->{{escape | mode = kill
| char=;
| {*{#invoke:Escape ; main ; mode {{=}} kill ;
<!--unescaped:-->{{#invoke:Escape/testcases|test_string2}}<br>; { }*}
| *
| {{!}} }}
}}
|
{{#invoke:Escape | main | mode = kill |
test { test {\{ test, \test, \{,test\ \ \ {\<br>| { }}
|
*
{{
;
|
Non-execution
After removal of the escape chars, the returned text is inert; i.e. not executed even without <pre>...</pre>
. (The above example is executed only because Tdemo forces execution.)
|mode=kill
with \{\{done\}\
\
{{done}}
Examples
Original:
test { test {\{ test, \test, \{,test\ \ \ {\
Using internal method to remove {
:
{
{{#invoke:Escape|main|mode=kill|test { test {\{ test, \test, \{,test\ \ \ {\|{}}
Using Treplace to remove {
:
{
{{#invoke:Escape|main|mode=undo|{{replace|{{#invoke:Escape|main|mode=text|test { test {\{ test, \test, \{,test\ \ \ {\}}|{|}}}}
No removal of {
between escape/unescape (escape char not restored):
{
{{#invoke:Escape|main|mode=undo
|{{#invoke:Escape|main|mode=text|test { test {\{ test, \test, \{,test\ \ \ {\}}
}}
Restore to original after escape
{{#invoke:Escape|main|mode=undo
|{{#invoke:Escape|main|mode=text|test { test {\{ test, \test, \{,test\ \ \ {\}}
|\
}}
Remove the word test
if not escaped and then place a different escape char in the place of the old escape char (for use by something else):
test
Note: The '%' char is a special in Lua, so use '%%' if that is the desired replacement. Otherwise, just a single char is fine (or a word).
{{#invoke:Escape|main|mode=kill
|test { test {\{ test, \test, \{,test\ \ \ {\
|test
|%%
}}