Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
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. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
Note: This module is used on a lot of pages. In order not to put too much load on the servers, edits should be kept to a bare minimum. Please discuss proposed changes on the talk page first.
|
heavily used module, because of {{Tle/parm}}, {{Igen/sub}} and {{Igen/top}}.
This module checks for some critical leading characters in the passed string,
and replaces them by their decimal numeric character references,
to avoid their interpretion as wiki syntax, and returns the (altered) string.
It can be invoked directly by either "Char|substitute
" or shorter by "Char|subst
"
or by using the Template:Charsubst: {{Charsubst|1= }}
#
, *
, :
and ;
. &
or<
are returned-as-they-are, but their bracketing, e.g. {{Charsubst|<}}, may avoid misinterpretion. |
(|) and =
(=) may cause problems within templates, but to substitute them by their decimal numeric character references won't help. |
by{{!}}
and =
by{{=}}
. |
by other characters, e.g the similar looking mathematical operator ∣
. This Unicode block contains also operators as −
, ∕
and ∗
. But neither in that block, nor among all the 1114112 Unicode characters is a substitute for the equal sign "=" known.See also Hilfe_Diskussion:Sonderzeichenreferenz#HTML_Entitäten_Tabelle
-- This function can substitute some critical leading characters
-- by their decimal numeric character references
-- to avoid their interpretion as wiki syntax
local ncr = {}
-- function: removes characters at the start of the string: '#', '*', ':', ';'
function ncr.subst ( frame )
local gpar = frame.args
local char = ''
if gpar then char = mw.text.trim ( gpar[1] )-- global
else char = mw.text.trim ( frame ) -- local
end
if mw.ustring.sub ( char, 1, 1 ) == '#' then
return '#' .. mw.ustring.sub( char, 2, #char );
elseif mw.ustring.sub ( char, 1, 1 ) == '*' then
return '*' .. mw.ustring.sub( char, 2, #char );
elseif mw.ustring.sub ( char, 1, 1 ) == ':' then
return ':' .. mw.ustring.sub( char, 2, #char );
elseif mw.ustring.sub ( char, 1, 1 ) == ';' then
return ';' .. mw.ustring.sub( char, 2, #char );
else
return char;
end
end -- end function subst
-- alias long function name for abbreviation
function ncr.substitute ( frame )
local gpar = frame.args
return ncr.subst ( gpar[1] );
end -- end function substitute
-- function: removes characters: '"', '&', "'", '<', '=', '>', '[', ']', '{', '|', '}'
function ncr.nowiki ( frame )
local gpar = frame.args
return mw.text.nowiki( gpar[1] );
end -- end function nowiki
return ncr;