模組:Separated entries
Kàu tō-lám
跳至搜尋
| 此Module已评为穩定版,稳定可靠,可各处使用无误。已可在帮助页面和其他维基百科资源中提及,以帮助新用户学习。为降低服务器负载和错误输出,改善本-{zh-cn:模块; zh-tw:模組;}-前应进行沙盒测试,而不是重复的试错性编辑。 |
| 此Module已被保护。此高度可见Module具有高風險,或已用于大量頁面或被频繁替换引用。由于破坏或失误影响程度嚴重,因此已被保护,只有錯誤:頁面未被保護。可以編輯。 |
-{H|zh-hans:重定向; zh-hant:閣再導向;}--{H|zh-cn:文字; zh-tw:字元;}--{H|zh-hans:文件; zh-hant:檔案;}--{H|zh-hans:快捷方式; zh-hant:捷徑;}--{H|zh-hans:項目; zh-hant:專案; zh-tw:計畫; zh-hk:計畫; zh-mo:計畫;}--{H|zh-cn:計算機; zh-sg:電腦; zh-tw:電腦;}-Lua 錯誤 於第53行的模組:Effective_protection_level中:attempt to index field 'TitleBlacklist' (a nil value)。
| 此Module被引用於許多頁面。 為了避免造成大規模的影響,所有對此Module的編輯應先於沙盒或測試樣例上測試。实施修改前,建议先在討論頁發起討論。 模板引用數量會自動更新。 |
用途
Module:Separated entries用作mw.text.listToText的模板前端,接收任意数量的位置参数,并使用|separator=将其连接起来。|conjunction=可用于为最后一个和倒数第二个项之间定义不同的间隔。开始的位置参数可使用|start=定义。开头的结尾的空白字符会被截去。如要刻意添加开头和结尾的空白字符,请使用 表示空格,或者使用 表示新行。空项不会产生任何错误。
{{#invoke:Separated entries|main|separator=...}}
参见
- {{Enum}}
- {{#invoke:params|function}}
-- This module takes positional parameters as input and concatenates them with
-- an optional separator. The final separator (the "conjunction") can be
-- specified independently, enabling natural-language lists like
-- "foo, bar, baz and qux".
local compressSparseArray = require('Module:TableTools').compressSparseArray
local p = {}
function p._main(args)
local separator = args.separator
-- Decode (convert to Unicode) HTML escape sequences, such as " " for space.
and mw.text.decode(args.separator) or ''
local conjunction = args.conjunction and mw.text.decode(args.conjunction) or separator
-- Discard named parameters.
local values = compressSparseArray(args)
return mw.text.listToText(values, separator, conjunction)
end
local function makeInvokeFunction(separator, conjunction)
return function (frame)
local args = require('Module:Arguments').getArgs(frame)
args.separator = separator or args.separator
args.conjunction = conjunction or args.conjunction
return p._main(args)
end
end
p.main = makeInvokeFunction()
p.br = makeInvokeFunction('<br />')
p.comma = makeInvokeFunction(mw.message.new('comma-separator'):plain())
return p