Difference between revisions of "Module:Escape/doc"
blackwiki>Codehydro (starting..) |
blackwiki>Codehydro (save) |
||
| Line 7: | Line 7: | ||
local escape = require('Module:Escape') | local escape = require('Module:Escape') | ||
| − | From a template: | + | From a template:<pre> |
{{invoke:Escape|main|mode=|char=}} | {{invoke:Escape|main|mode=|char=}} | ||
| − | + | </pre> | |
By default, this module will escape the {{code|\}} char. To escape the {{code|{}} char instead, you can do {{code|require('Module:Escape'):char('{')}} (or {{code|esc:char('{')}} if you've stored table returned by this module in the local variable {{code|esc}}). When used in a template, set {{para|char}} equal to the char code. | By default, this module will escape the {{code|\}} char. To escape the {{code|{}} char instead, you can do {{code|require('Module:Escape'):char('{')}} (or {{code|esc:char('{')}} if you've stored table returned by this module in the local variable {{code|esc}}). When used in a template, set {{para|char}} equal to the char code. | ||
| − | {{#invoke:Escape|main|mode=kill|test { | + | ===Template Example=== |
| − | + | While other modes are available, only <code>|mode=kill</code> is probably the one most useful outside of Module space. The first parameter is your text with escaped chars. The second parameter is a char or string or pattern you wish to remove. | |
| − | + | <pre> | |
| − | + | {{#invoke:Escape|main | |
| − | + | |mode=kill | |
| − | + | |test { test {\{ test, \test, \{,test\ \\ \ {\ , | |
| + | |{ | ||
| + | }} | ||
| + | </pre> | ||
| + | {{#invoke:Escape|main | ||
| + | |mode=kill | ||
| + | |test { test {\{ test, \test, \{,test\ \\ \ {\ , | ||
| + | |{ | ||
| + | }} | ||
| + | ===Module Example=== | ||
Here's some sample output from the debug consol below the module editor: | Here's some sample output from the debug consol below the module editor: | ||
{|- class='wikitable' | {|- class='wikitable' | ||
| | | | ||
| − | {{blue|'''local escape {{=}} require('Module:Escape')<br>test {{=}} 'test, \\test, \\{,test\\\\ \\\\ \\\\\\\\'<br><br>test2 {{=}} escape: | + | {{blue|'''local escape {{=}} require('Module:Escape')<br>test {{=}} 'test, \\test, \\{,test\\\\ \\\\ \\\\\\\\'<br><br>test2 {{=}} escape:char('{'):text(test)<br>{{=}}test2'''}}<br> |
| − | test, \test, \�7b�44�7btest\\ \\ \\\\ | + | test, \test, \�7b�44�7btest\\ \\ \\\\ |
| − | {{blue|'''test3 {{=}} escape: | + | |
| − | test, �5c�116�5cest, �5c�24�5c7b�44�7btest�5c�92�5c �5c�92�5c �5c�92�5c�5c�92�5c | + | {{blue|'''test3 {{=}} escape:char('\\'):text(test2)<br><br>{{=}}test3'''}}<br> |
| − | {{blue|'''test4 {{=}} escape: | + | test, �5c�116�5cest, �5c�24�5c7b�44�7btest�5c�92�5c �5c�92�5c �5c�92�5c�5c�92�5c |
| − | test, �5c�116�5cest, �5c�24�5c7b�44�7btest�5c�92�5c �5c�92�5c �5c�92�5c�5c�92�5c | + | |
| − | {{blue|'''test4 {{=}} escape: | + | {{blue|'''test4 {{=}} escape:char('{', {undo {{=}} test3})<br><br>{{=}}test4'''}}<br> |
| + | test, �5c�116�5cest, �5c�24�5c7b�44�7btest�5c�92�5c �5c�92�5c �5c�92�5c�5c�92�5c | ||
| + | |||
| + | {{blue|'''test4 {{=}} escape:char('\\', {undo {{=}} test3})<br><br>{{=}}test4'''}}<br> | ||
test, \test, \�7b�44�7btest\\ \\ \\\\<br><br> | test, \test, \�7b�44�7btest\\ \\ \\\\<br><br> | ||
| − | {{blue|'''test5 {{=}} escape: | + | {{blue|'''test5 {{=}} escape:char('{', {undo {{=}} test4})<br><br>{{=}}test5 {{=}}{{=}} test'''}}<br> |
true<br><br> | true<br><br> | ||
'''{{blue|{{=}}escape:undo(test3)}}'''<br> | '''{{blue|{{=}}escape:undo(test3)}}'''<br> | ||
| − | test, �5c�116�5cest, �5c�24�5c7b�44�7btest�5c�92�5c �5c�92�5c �5c�92�5c�5c�92�5c | + | test, �5c�116�5cest, �5c�24�5c7b�44�7btest�5c�92�5c �5c�92�5c �5c�92�5c�5c�92�5c |
| + | |||
'''{{blue|{{=}}escape:undo(test4)}}<br> | '''{{blue|{{=}}escape:undo(test4)}}<br> | ||
| − | test, \test, \,test\\ \\ \\\\ | + | test, \test, \,test\\ \\ \\\\ |
| − | '''{{blue|{{=}}escape: | + | |
| − | test, test, �7b�44�7btest\ \ \\ | + | '''{{blue|{{=}}escape:char('\\'):undo(test3)}}<br> |
| − | '''{{blue|{{=}}escape: | + | test, test, �7b�44�7btest\ \ \\ |
| − | test, test, {,test\ \ \\ | + | |
| − | '''{{blue|{{=}}test {{=}}{{=}} escape: | + | '''{{blue|{{=}}escape:char('{', {undo {{=}} escape:char('\\'):undo(test3)})}}<br> |
| − | false | + | test, test, {,test\ \ \\ |
| − | '''{{blue|{{=}}test {{=}}{{=}} escape: | + | |
| + | '''{{blue|{{=}}test {{=}}{{=}} escape:char('{', {undo {{=}} escape:char('\\'):undo(test3)})}}<br> | ||
| + | false | ||
| + | |||
| + | '''{{blue|{{=}}test {{=}}{{=}} escape:char('{', {undo {{=}} escape:char('\\'):undo(test3, '\\')})}}<br> | ||
true | true | ||
| + | |||
| + | '''{{blue|local t {{=}} 'test { test {\\{ test, \\test, \\{,test\\ \\ \\ {\\'<br>{{=}}t}}<br>''' | ||
| + | test { test {\{ test, \test, \{,test\ \ \ {\ | ||
| + | |||
| + | '''{{blue|local e {{=}} require('Module:Escape')<br>local t2 {{=}} escape:text(t)<br>local t3 {{=}} string.gsub(t2, '{', '')<br>local t4 {{=}} escape:undo(t3)<br>{{=}}t4}}<br>''' | ||
| + | test test { test, test, {,test \ | ||
| + | |||
| + | '''{{blue|local tk0 {{=}} escape:kill(t, '{')<br>{{=}}tk0 {{=}}{{=}} t4}}<br>''' | ||
| + | true | ||
| + | |||
| + | |||
|} | |} | ||
Revision as of 02:40, 14 January 2015
| 40x40px | This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
Usage
This module is designed as an way to escape strings in a customized manner. There are two ways to call this module:
From another module:
local escape = require('Module:Escape')
From a template:
{{invoke:Escape|main|mode=|char=}}
By default, this module will escape the \ char. To escape the { char instead, you can do require('Module:Escape'):char('{') (or esc:char('{') if you've stored table returned by this module in the local variable esc). When used in a template, set |char= equal to the char code.
Template Example
While other modes are available, only |mode=kill is probably the one most useful outside of Module space. The first parameter is your text with escaped chars. The second parameter is a char or string or pattern you wish to remove.
{{#invoke:Escape|main
|mode=kill
|test { test {\{ test, \test, \{,test\ \\ \ {\ ,
|{
}}
test test { test, test, {,test \ ,
Module Example
Here's some sample output from the debug consol below the module editor:
|
local escape = require('Module:Escape') test3 = escape:char('\\'):text(test2) test4 = escape:char('{', {undo = test3}) test4 = escape:char('\\', {undo = test3}) =escape:undo(test4) =escape:char('\\'):undo(test3) =escape:char('{', {undo = escape:char('\\'):undo(test3)}) =test == escape:char('{', {undo = escape:char('\\'):undo(test3)}) =test == escape:char('{', {undo = escape:char('\\'):undo(test3, '\\')}) local t = 'test { test {\\{ test, \\test, \\{,test\\ \\ \\ {\\' local e = require('Module:Escape') local tk0 = escape:kill(t, '{')
|