跳转到内容

模組:Chemicals

被永久保护的模块
维基百科,自由的百科全书

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

local p = {}
local origArgs
local error = require( 'Module:Error' )
local element= require( 'Module:Element' )

function p.formula(frame)
	-- For calling from #invoke.
	local pframe = frame:getParent()
	local args = pframe.args
	return p._formula(args)
end

function p._formula(args)
	local body = ''
	for v, x in ipairs(args) do 
		number=tonumber(x)
		if(number)then
			if(body == '')then body = x .. body else body = body .. '<sub>' .. x .. '</sub>' end
		else
			body = body .. element._elementlink({x})
		end
	end
	return body
end

function p._formula1(args)
	local body = ''
	last=''
	for v, x in ipairs(args) do 
		number=tonumber(x)
		lastn=tonumber(last)
		if(number)then
			if((not (lastn)) and last ~= '')then
				body = body .. element._elementlink({last,x})
			else if(body == '' and last == '')then
				body = x .. body 
			else if (lastn)then
				if(lastn==1)then
					body = body .. '<sup>+</sup>'
				else if(lastn==-1)then
					body = body .. '<sup>-</sup>'
				else if(lastn>0)then
					body = body .. '<sup>'.. lastn ..'+</sup>'
				else if(lastn<0)then
					body = body .. '<sup>'.. lastn ..'-</sup>'
				end end end end
			end end end
		else
			if ((not (lastn)) and last ~= '') then
				if (last == '+') then
					body = body .. ' + '
				else if (last == '=' or last == '→') then
					body = body .. ' → '
				else if (last == '==' or last == 'eqm') then
					body = body .. ' [[File:Equilibrium.svg|15px|化学平衡符号]] '
				end end end
				body = body .. element._elementlink({last})
			end
		end
		last=x
	end
	return body
end

--本模塊的沙盒(測試)函數
function p.sandbox(frame)
	-- For calling from #invoke.
	local pframe = frame:getParent()
	local args = pframe.args
	return p._formula1(args)
end
function p._sandbox(args)
	return element_data[p.getListID(args[1])].name 
end
return p