模块:Zhchar:修订间差异

删除183字节 、​ 2024年3月17日 (星期日)
//Edit via InPageEdit
(//Edit via InPageEdit)
(//Edit via InPageEdit)
第1行:
local p = {}
p.zhchar = function( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local zhchar = {}
for _, key in ipairs( args ) do
key = mw.text.trim( key )
if key ~= '+' and key:find( '%+' ) then
local combozhchar = {}
for comboKey in mw.text.gsplit( key, '%s*%+%s*' ) do
table.insert( combozhchar, p.key( comboKey ) )
end
table.insert( zhchar, table.concat( combozhchar, ' + ' ) )
else
table.insert( zhchar, p.key( key ) )
end
end
return table.concat( zhchar )
end
 
p.keyzhchar = function( key frame)
local args = fframe
if key == '' then
if fframe == mw.getCurrentFrame() then
return ''
args = fframe:getParent().args
end
end
 
local zhchar = {}
local symbols = mw.loadData( 'Module:Zhchar/Symbols' )
local rareCharPattern = '{{RareChar|%s*([^|}]+)%s*|%s*([^|}]+)%s*}}'
local rareCharReplacement = function( rareChar, rareCharArgs )
return mw.getCurrentFrame():expandTemplate{ title = 'RareChar', args = { rareChar, rareCharArgs } }
end
 
for _, key in ipairs( args ) do
local replacedKey = key:gsub(rareCharPattern, rareCharReplacement)
key = mw.text.trim( key )
if key ~= '+' and key:find( '%+' ) then
return ( symbols[replacedKey] or replacedKey )
local combozhchar = {}
for comboKey in mw.text.gsplit( key, '%s*%+%s*' ) do
table.insert( combozhchar, p.key( comboKey ) )
end
table.insert( zhchar, table.concat( combozhchar, ' + ' ) )
else
table.insert( zhchar, p.key( key ) )
end
end
 
return mw.text.unstrip(table.concat( zhchar ))
end
 
p.zhcharkey = function( f key)
if key == '' then
return ''
end
 
local symbols = mw.loadData( 'Module:Zhchar/Symbols' )
return mw.text.unstrip(symbols[key] or key)
end
 
return p
2,007

个编辑