Content deleted Content added
Copy from sandbox per request on talk |
Take two |
||
Line 96:
function p._Zh(args)
if args["link"] then args["links"] = args["link"]; end
if args["label"] then args["labels"] = args["label"]; end
local uselinks = args["links"] ~= "no" -- whether to add links
local uselabels = args["labels"] ~= "no" -- whether to have labels
local capfirst = args["scase"] ~= nil
local out = nil -- which term to put before the brackets
local usebrackets =
local numargs = 0
if args["out"] then
out = args["out"]
usebrackets =
end
Line 138 ⟶ 143:
orderlist[9] = "w"
end
if out then▼
for i, v in ipairs (orderlist) do▼
if v == out then▼
table.remove(orderlist, i)▼
table.insert(orderlist, 1, v)▼
break▼
end▼
end▼
end▼
-- rename rules. Rules to change parameters and labels based on other parameters
if args["hp"] then
Line 170 ⟶ 167:
labels["t"] = labels["c"]
end
▲ if out then
▲ for i, v in ipairs (orderlist) do -- shift `out` to the beginning of the order list
▲ if v == out then
▲ table.remove(orderlist, i)
▲ table.insert(orderlist, 1, v)
▲ break
▲ end
▲ end
▲ end
if (out == "c" and args["s"]) then usebrackets = 2; end
local body = "" -- the output string
Line 179 ⟶ 187:
for i, part in ipairs(orderlist) do
if (args[part]) then
numargs = numargs + 1
-- build label
label = ""
Line 187 ⟶ 196:
capfirst = false
end
if (uselinks and part ~= "l" and part ~= "tr") then
label = "[[" .. wlinks[part] .. "|" .. label .. "]]"
end
if (
label = "<abbr title=\"" .. wlinks[part] .. "\"><small>" .. label .. "
else
label =
end
label = label .. " "
Line 212 ⟶ 221:
for term in val:gmatch("[^;,]+") do
term = string.gsub(term, "^([ \"']*)(.*)([ \"']*)$", "%2")
▲ terms = terms .. "'" .. term .. "', "
end
val = string.sub(terms, 1, -3)
elseif (part == "tr") then
-- put translations in double quotes
val = "
end
if (italic[part]) then
Line 230 ⟶ 238:
end
-- add both to body
if
-- opening bracket after the `out` term
body = body .. label .. val .. " ("
else
body = body .. label .. val .. "; "
Line 241 ⟶ 249:
if (body > "") then -- check for empty string
body = string.sub(body, 1, -3) -- chop off final semicolon and space
if out and numargs > usebrackets then
-- closing bracket after the rest of the terms
body = body .. "
end
return body
Line 255 ⟶ 263:
label = "[[" .. wlinks["c"] .. "|" .. label .. "]]"
end
label = label .. "&
end
-- default to show links and labels as no options given
|