模組:Ex

維基詞典,自由的多語言詞典

本模块用于{{ex}}


return {
	main=function(frame)
		local t={}
		local word=tostring(mw.title.getCurrentTitle())
		local args=frame:getParent().args
		--获取参数表
		for k,v in pairs(args) do
			if k=='title' then
				word=v
				--将title的值计入word变量中,其他的则计入t表中。
			elseif type(k)=='number' then
				table.insert(t,v)
			elseif type(k)=='string' then
				table.insert(t,k..'='..v)
				--对于维基文本参数中类似于a=b的文本,计入表中为"a=b",而非['a']="b"
			end
		end
		-- 此时t是纯净的参数序列的表,每个域的键都是数字。
		for k,v in ipairs(t) do
			local span=mw.html.create'span'
				:addClass'example'
				:wikitext(v:gsub('~',("'''"..word.."'''"))..'')--将波浪号替换为加粗的标题名称
			t[k]=tostring(span)--直接修改t的相应的域
		end
		return "'''例:'''"..table.concat(t,'|')
	end
}