• Home
  • Random
  • Log in
  • Settings
  • About Safer nicotine wiki
  • Disclaimers
Safer nicotine wiki

Template:Escape

  • Language
  • Watch
  • View source
Template documentation[view] [edit] [history] [purge]
This article provides insufficient context for those unfamiliar with the subject. Please help improve the article by providing more context for the reader. (Learn how and when to remove this message)
This template uses Lua:
  • Module:Escape

Contents

  • 1 Usage
    • 1.1 Non-execution
  • 2 Examples
    • 2.1 Original:
    • 2.2 Using internal method to remove {:
    • 2.3 Using {{replace}} to remove {:
    • 2.4 No removal of { between escape/unescape (escape char not restored):
    • 2.5 Restore to original after escape
    • 2.6 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):

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, {{demo}} 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 {{demo}}, 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\ \ \ {\
| { }}

test test { test, test, {,test

Note how the * character, used to break up the {{ to prevent execution, is removed and how the ; character is replaced by |.

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 {{demo}} forces execution.)

For example, setting |mode=kill with \{\{done\}\} as the first parameter and nothing else will simply cause the default escape character \ to be removed:

{{done}}

Examples

Original:

test { test {\{ test, \test, \{,test\ \ \ {\

Using internal method to remove {:

{{escape|mode=kill|test { test {\{ test, \test, \{,test\ \ \ {\|{}}
test test { test, test, {,test \

Using {{replace}} to remove {:

{{escape|mode=undo|{{replace|{{escape|mode=text|test { test {\{ test, \test, \{,test\ \ \ {\}}|{|}}}}
test test { test, test, {,test \

No removal of { between escape/unescape (escape char not restored):

{{escape|mode=undo
|{{escape|mode=text|test { test {\{ test, \test, \{,test\ \ \ {\}}
}}
test { test {{ test, test, {,test {\

Restore to original after escape

{{escape|mode=undo
|{{escape|mode=text|test { test {\{ test, \test, \{,test\ \ \ {\}}
|\
}}
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):

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).

{{escape|mode=kill
|test { test {\{ test, \test, \{,test\ \ \ {\
|test
|%%
}}
{ {%{ , %test, %{,% % % {\
The above documentation is transcluded from Template:Escape/doc. (edit | history)
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this template.
Retrieved from "https://safernicotine.wiki/mediawiki/index.php?title=Template:Escape&oldid=20492"
Last edited on 27 December 2021, at 09:05
Cookies help us deliver our services. By using our services, you agree to our use of cookies.
More information

Languages

      This page is not available in other languages.

      Safer nicotine wiki
      • This page was last modified on 27 December 2021, at 09:05. Warning: Page may not contain recent updates.
      • Content is available under Creative Commons Attribution-ShareAlike unless otherwise noted.
      • Privacy policy
      • About Safer nicotine wiki
      • Disclaimers
      • Terms of Use
      • Desktop
      • Data access
      • Developers
      • Statistics
      • Cookie statement