local z = {}
local error = require( 'Module:Error' )
local function makeText( frame, v )
local text = v.text
if not v.preprocessed then
text = frame:preprocess( text )
end
return mw.text.trim( text ) .. '\n'
end
local function makeItem( frame, v )
local text = '* '
if v.original then
text = text .. '原文:' .. v.original .. ';'
end
return text .. '-{D|' .. v.rule .. '}-当前显示为:-{|' .. v.rule .. '}-\n'
end
function z.sandboxshow( frame )
local name = frame.args[1]
if not name or name == '' then
return ''
end
local data = require( 'Module:' .. name )
local text = '-{H|zh-hans:模块;zh-hant:模組}-<strong>以下是[[Wikipedia:字詞轉換處理/公共轉換組|公共转换组]]“' .. data.description .. '”的沙盒。</strong>\n\n'
for i, v in ipairs( data.content ) do
if v.type == 'text' then
text = text .. makeText( frame, v )
elseif v.type == 'item' then
text = text .. makeItem( frame, v )
end
end
text = text .. '[[Category:公共转换组模块|sandbox]]'
return text
end
function z._conversion(frame, args)
local name = args[1]
if not name or name == '' then
return ''
end
local data = require( 'Module:CGroup/' .. name )
if type( data ) ~= 'table' or not data.name or data.name == '' then
return error.error{ '指定-{zh-hans:模块;zh-hant:模組};-“' .. name .. '”不是有效的转换组' }
end
local text = string.format([=[
<!--
公共转换组%s
https://zh.wikipedia.org/wiki/Module:CGroup/%s
\n
公共轉換組%s
https://zh.wikipedia.org/wiki/Module:CGroup/%s
這是此公共轉換組的純轉換版
\n
Chinese Conversion Group(CGroup) - %s
Copy from https://zh.wikipedia.org/wiki/Module:CGroup/%s
You can use {{#invoke:CGroupViewer2|main|%s}} in chinese wikipedia to find they.
-->
]=], name, name, name, name, name, name, name)
for i, v in ipairs( data.content ) do
if v.type == 'text' then
if not v.preprocessed then
text = text .. '<!--\n' .. v.text .. '-->\n'
end
elseif v.type == 'item' then
if v.original then
text = text .. '-{H|' .. v.rule .. '}-<!--' .. v.original .. '-->\n'
else
text = text .. '-{H|' .. v.rule .. '}-\n'
end
end
end
text = text .. ''
return text
end
function z.main( frame )
local args = {}
for k, v in pairs( frame.args ) do
args[k] = v
end
return '<div style="dispaly:none">' .. string.gsub(z._conversion(frame, args), '\\n', '----') .. '</div>'
end
function z.main2( frame )
local args = {}
for k, v in pairs( frame.args ) do
args[k] = v
end
local pre = string.format('<pre>%s</pre>', z._conversion(frame, args))
pre = string.gsub(pre, '!', '!')
pre = string.gsub(pre, '=', '=')
pre = string.gsub(pre, 'h', 'h')
pre = string.gsub(pre, '%[', '[')
pre = string.gsub(pre, '%]', ']')
pre = string.gsub(pre, '{', '{')
pre = string.gsub(pre, '|', '|')
pre = string.gsub(pre, '}', '}')
pre = string.gsub(pre, '{{', '{{')
pre = string.gsub(pre, '\\n', '----')
return pre
end
function z.showlua(frame, args)
local name = frame.args[1]
if not name or name == '' then
return ''
end
local data = require( 'Module:CGroup/' .. name )
if type( data ) ~= 'table' or not data.name or data.name == '' then
return error.error{ '指定-{zh-hans:模块;zh-hant:模組};-“' .. name .. '”不是有效的转换组' }
end
return mw.getCurrentFrame():preprocess('<syntaxhighlight lang="lua">' .. mw.title.new('Module:CGroup/' .. name):getContent() .. '</syntaxhighlight>')
end
return z