跳转到内容

模組:NumBlk2

本页使用了标题或全文手工转换
维基百科,自由的百科全书

local p = {}

function dbgWrap(str, frame)
	return "<div class=\"numblk2-dbg\" style=\""
		.. "display: inline-block; border: thin dashed; width: min-content; vertical-align: middle;"
		.. " font-family: monospace; font-weight: normal; white-space: pre-wrap; overflow: auto;" ..
	"\">" .. frame:preprocess("<nowiki>" .. mw.text.encode(str) .. "</nowiki>") .. "&sext;</div>"
end

function p.fmtN(frame)
	local frame2 = frame:getParent()
	local code = frame.args[1]
	local code2 = mw.text.unstripNoWiki(code)
	local code3 = mw.ustring.gsub(
		code2, "%%(.)", function (ch)
			if (ch == "i") or (ch == "l") then
				return frame.args[ch]
			elseif ch == "L" then
				return "<";
			elseif ch == "G" then
				return ">";
			end
			return ch
		end
	)
	local ret = frame2:preprocess(code3)
	if (frame.args.dbg or ""):find("%S") then
		return dbgWrap(
			"FMT=" .. code .. "; ID=" .. frame.args.i .. "; LBL=" .. frame.args.l .. ";"
			.. " UST=" .. code2 .. "; SUB=" .. code3 .. "; EXP=" .. ret .. ";", frame2
		) .. ret
	end
	return ret
end

return p