模块:Example:修订间差异
来自 LNN的:not(博客)?
更多操作
小无编辑摘要 |
小无编辑摘要 |
||
| (未显示同一用户的2个中间版本) | |||
| 第3行: | 第3行: | ||
local getArgs = require("Module:Arguments").getArgs | local getArgs = require("Module:Arguments").getArgs | ||
function p._example(frame, code) | function p._example(frame, code, rh) | ||
libraryUtil.checkType("_example", 1, frame, "table") | libraryUtil.checkType("_example", 1, frame, "table") | ||
libraryUtil.checkType("_example", 2, code, "string") | 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 source = mw.text.tag("pre", {}, mw.text.nowiki(code)) | ||
local result = frame:preprocess(code) | local result = frame:preprocess(code) | ||
return source | if rh then | ||
return source .. "\n\n" .. rh .. "\n\n" .. result | |||
else | |||
return source .. "\n\n" .. result | |||
end | |||
end | end | ||
function p.example(frame) | function p.example(frame) | ||
local args = getArgs(frame, { trim = false }) | local args = getArgs(frame, { trim = false }) | ||
local str = args[1] | local str = args[1] | ||
str = mw.text.unstrip(str) | str = mw.text.unstrip(str) | ||
str = mw.text.decode(str) | str = mw.text.decode(str) | ||
str = mw.text.trim(str, "\n") | str = mw.text.trim(str, "\n") | ||
return p._example(frame, str) | local rh = args.resultheader | ||
return p._example(frame, str, rh) | |||
end | end | ||
return p | return p | ||
2023年2月26日 (日) 09:49的最新版本
此模块的文档可以在模块: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