440
edits
(Generic implementation of Module:Br separated entries) |
m (16 revisions imported from templatewiki:Module:Separated_entries) |
||
(15 intermediate revisions by 7 users not shown) | |||
Line 1:
-- This module takes positional parameters as input and concatenates them with
local getArgs = require('Module:Arguments').getArgs▼
-- an optional separator. The final separator (the "conjunction") can be
-- specified independently, enabling natural-language lists like
-- "foo, bar, baz and qux". The starting parameter can also be specified.
local compressSparseArray = require('Module:TableTools').compressSparseArray
local p = {}
function p.
local
-- Decode (convert to Unicode) HTML escape sequences, such as " " for space.
and mw.text.decode(args.separator) or ''
-- Discard values before the starting parameter.
return p._main(args)▼
local start = tonumber(args.start)
if start then
for i = 1, start - 1 do args[i] = nil end
local values = compressSparseArray(args)
end
local separator = origArgs.separator or ''▼
▲ local conjunction = origArgs.conjunction or separator
local function makeInvokeFunction(separator, conjunction, first)
return function (frame)
▲ -- Discard named parameters.
args.conjunction = conjunction or args.conjunction
args.first = first or args.first
▲ end
end
▲ return mw.text.listToText(args, separator, conjunction)
end
p.main = makeInvokeFunction()
p.br = makeInvokeFunction('<br />')
p.comma = makeInvokeFunction(mw.message.new('comma-separator'):plain())
return p
|