„Modul:Char“ – Versionsunterschied
aus Wikipedia, der freien Enzyklopädie
imported>Sarang(584540) (first version) |
K (Protected "Module:Char": High-risk Lua module ([Edit=Allow only template editors and administrators] (indefinite) [Move=Allow only template editors and administrators] (indefinite))) |
||
Zeile 1: | Zeile 1: | ||
-- This function can substitute some critical leading characters | |||
-- by their decimal numeric character references | |||
-- to avoid their interpretion as wiki syntax | |||
local ncr = {} | |||
function | -- function: removes characters at the start of the string: '#', '*', ':', ';' | ||
local | function ncr.subst ( frame ) | ||
local gpar = frame.args | |||
local char = '' | |||
return '#' .. mw.ustring.sub( | if gpar then char = mw.text.trim ( gpar[1] )-- global | ||
elseif mw.ustring.sub ( | else char = mw.text.trim ( frame ) -- local | ||
return '*' .. mw.ustring.sub( | end | ||
elseif mw.ustring.sub ( | if mw.ustring.sub ( char, 1, 1 ) == '#' then | ||
return ':' .. mw.ustring.sub( | return '#' .. mw.ustring.sub( char, 2, #char ); | ||
elseif mw.ustring.sub ( | elseif mw.ustring.sub ( char, 1, 1 ) == '*' then | ||
return ';' .. mw.ustring.sub( | 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 | else | ||
return | return char; | ||
end | end | ||
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 | |||
return | |||
-- function: removes characters: '"', '&', "'", '<', '=', '>', '[', ']', '{', '|', '}' | |||
function ncr.nowiki ( frame ) | |||
local gpar = frame.args | |||
return mw.text.nowiki( gpar[1] ); | |||
end -- end function nowiki | |||
return ncr; |
Version vom 18. Oktober 2020, 12:01 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Char/Doku erstellt werden
-- 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;