Module:Char

From IxWiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Char/doc

-- This function can substitute some critical leading characters
-- by their decimal numeric character references
-- to avoid their interpretion as wiki syntax

local ncr = {}

-- global=args[1] / local=frame
function ncr.substitute ( frame )
	local args  = frame.args
	local char  = ''
	if  args then
          char  = args[1]
	else
          char  = frame
	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 '&#59;' .. mw.ustring.sub( char, 2, #char );
    else
         return char;
    end
end

-- alias function name (abbreviation)
function   ncr.subst      ( frame )
	local args  = frame.args
	local str   = args[1]
	return ncr.substitute ( str )
end

return ncr;