模組:沙盒/Sunny00217/LetParseLikeInTemplate

维基百科,自由的百科全书
文档图示 模块文档[创建]
return {
	[''] = function (frame)
		local root = frame.args.root
		local ns10prexfix = frame.args.ns10prefix or 'Template:'
		local q = mw.text.unstripNoWiki(frame.args[1])
		q:gsub('{{([^<>%[%]{}%|%=}]+)([%|}])', function (n, p) 
			s, t = pcall(mw.title.new, n)
			if not s or not t then
				return '{{<kill />' .. n .. p
			end
			if t.namespace == 0 and n:match('^%:') then
				return '{{' .. root .. ns10prexfix .. t.fullText .. p
			else
				return '{{' .. root .. t.fullText .. p
			end
		end)
		return frame:preprocess(q:gsub('<kill />', ''))
	end
}