跳转到内容

模組:CGroupViewer2

维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2019年12月14日 (六) 07:41编辑。这可能和当前版本存在着巨大的差异。

local z = {}
local error = require( 'Module:Error' )

function 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
这是此公共转换组的纯转换版
----
公共轉換組%s
https://zh.wikipedia.org/wiki/Module:CGroup/%s
這是此公共轉換組的純轉換版
----
Chinese Conversion Group(CGroup) - %s
Copy from https://zh.wikipedia.org/wiki/Module:CGroup/%s
-->
]=], 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 conversion(frame, args)
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>', conversion(frame, args))
	pre = string.gsub(pre, '!', '&#33;')
	pre = string.gsub(pre, '=', '&#61;')
	pre = string.gsub(pre, 'h', '&#104;')
	pre = string.gsub(pre, '%[', '&#91;')
	pre = string.gsub(pre, '%]', '&#93;')
	pre = string.gsub(pre, '{', '&#123;')
	pre = string.gsub(pre, '|', '&#124;')
	pre = string.gsub(pre, '}', '&#125;')
	pre = string.gsub(pre, '{{', '&#123;&#123;')
	return pre
end


return z