欢迎来到奇葩栖息地!欢迎加入Discord服务器:XfrfHCzfbW。请先至特殊:参数设置验证邮箱后再进行编辑。在特殊:参数设置挑选自己想要使用的小工具!不会编辑?请至这里学习Wikitext语法。
模块:Zhchar
来自奇葩栖息地
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
-- Process the returned content to expand Rarechar templates
local result = table.concat( zhchar )
result = mw.text.unstripNoWiki(result) -- Ensure no wiki parsing occurs
result = mw.text.expandTemplate(result) -- Expand templates
return result
end
p.key = function( key )
if key == '' then
return ''
end
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
local replacedKey = key:gsub(rareCharPattern, rareCharReplacement)
return ( symbols[replacedKey] or replacedKey )
end
return p