local p = {}
local zhcv = require('Module:ZhConversion')
local function process(variant, content, args)
local result = content
-- 应用文本转换
if variant == 'zh-cn' then
result = zhcv.to_cn(result)
elseif variant == 'zh-hans' then
result = zhcv.to_hans(result)
elseif variant == 'zh-tw' then
result = zhcv.to_tw(result)
elseif variant == 'zh-hk' then
result = zhcv.to_hk(result)
elseif variant == 'zh-hant' then
result = zhcv.to_hant(result)
end
return result
end
function p.main(frame)
local args = frame:getParent().args
local content = mw.text.unstripNoWiki(args[1]):gsub('<', '<'):gsub('>', '>')
table.remove(args, 1)
-- 为各变体生成高亮内容
local zh_cn_content = process('zh-cn', content, args)
local zh_tw_content = process('zh-tw', content, args)
local zh_hk_content = process('zh-hk', content, args)
-- 构建转换标记
local converted = '-{' ..
'zh-cn:' .. mw.getCurrentFrame():extensionTag('syntaxhighlight', zh_cn_content, args) .. ';' ..
'zh-tw:' .. mw.getCurrentFrame():extensionTag('syntaxhighlight', zh_tw_content, args) .. ';' ..
'zh-hk:' .. mw.getCurrentFrame():extensionTag('syntaxhighlight', zh_hk_content, args) .. ';' ..
'}-'
return converted
end
return p