Content deleted Content added
check_sandbox includes a diff link |
better emulation of how MediaWiki parses parameters to a template |
||
Line 78:
local function run_template(frame, template, collapse_multiline)
-- Template "{{ example | 2 = def | abc | name = ghi jkl }}"
if template:sub(1, 2) == '{{' and template:sub(-2, -1) == '}}' then
template = template:sub(3, -3) .. '|' -- append sentinel to get last field
else
return '(invalid template)'
end
local args = {}
local index = 1
for item in string.gmatch(argstr .. '|', '(.-)|') do▼
if p then▼
if templatename == nil then
templatename = strip(field)
if templatename == '' then
return '(invalid template)'
end
else
k, v = strip(k), strip(v) -- k and/or v can be empty
local i = tonumber(k)
if i and i > 0 and string.match(k, '^%d+$') then
args[i] = v
else
args[k] = v
end
else
while args[index] ~= nil do
-- Skip any explicit numbered parameters like "|5=five".
index = index + 1
end
args[index] = field
end
end
end
Line 94 ⟶ 116:
return frame:expandTemplate(t)
end
local ok, result = pcall(expand, { title =
if not ok then
result = 'Error: ' .. result
|