模块:Example
可在模块:Example/doc创建此模块的帮助文档
local p = {}
local libraryUtil = require("libraryUtil")
local getArgs = require("Module:Arguments").getArgs
function p._example(frame, code, rh)
libraryUtil.checkType("_example", 1, frame, "table")
libraryUtil.checkType("_example", 2, code, "string")
libraryUtil.checkType("_example", 3, rh, "string", --[[ nilOk= ]] true)
local source = mw.text.tag("pre", {}, mw.text.nowiki(code))
local result = frame:preprocess(code)
if rh then
return source .. "\n\n" .. rh .. "\n\n" .. result
else
return source .. "\n\n" .. result
end
end
function p.example(frame)
local args = getArgs(frame, { trim = false })
local str = args[1]
str = mw.text.unstrip(str)
str = mw.text.decode(str)
str = mw.text.trim(str, "\n")
local rh = args.resultheader
return p._example(frame, str, rh)
end
return p