Difference between revisions of "Module:Cslist"
Jump to navigation
Jump to search
blackwiki>MusikBot II m (Protected "Module:Cslist": High-risk template or module (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite))) |
m (7 revisions imported) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 9: | Line 9: | ||
local semi = (args.semi or ""):sub(1,1):lower() | local semi = (args.semi or ""):sub(1,1):lower() | ||
semi = (semi == "t") or (semi == "y") | semi = (semi == "t") or (semi == "y") | ||
| + | local embedded = (args.embedded or ""):sub(1,1):lower() | ||
| + | embedded = (embedded == "y") | ||
local out = "" | local out = "" | ||
for k, v in ipairs(args) do | for k, v in ipairs(args) do | ||
| Line 15: | Line 17: | ||
out = out .. "<li>" .. v .. "</li>" | out = out .. "<li>" .. v .. "</li>" | ||
end | end | ||
| + | end | ||
| + | local listclass = "" | ||
| + | if semi then | ||
| + | listclass = listclass .. "sslist" | ||
| + | else | ||
| + | listclass = listclass .. "cslist" | ||
| + | end | ||
| + | if embedded then | ||
| + | listclass = listclass .. " cslist-embedded" | ||
end | end | ||
if out ~= "" then | if out ~= "" then | ||
| − | + | return '<ul class="'.. listclass ..'">' .. out .. '</ul>' | |
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
end | end | ||
return p | return p | ||
Latest revision as of 15:59, 26 September 2020
Module to implement Template:Cslist, which creates a horizontal list similar to Template:Hlist but using comma separators instead of mid-dots.
It can take as many list items as desired, and also an optional |semi=, which when set to true or yes will use a semicolon as separator in place of the comma.
Note: the unordered list which is generated is good for accessibility, but really is only useful in tables and infoboxes as an alternative to using {{hlist}}. It should not be used in running prose.
Examples
{{cslist | first item | second item | third item | etc}} →
|
{{cslist | first item | second item | third item | etc |semi=true}} →
|
p = {}
p.makelist = function(frame)
local args = frame.args
if not args[1] then
args = frame:getParent().args
if not args[1] then return end
end
local semi = (args.semi or ""):sub(1,1):lower()
semi = (semi == "t") or (semi == "y")
local embedded = (args.embedded or ""):sub(1,1):lower()
embedded = (embedded == "y")
local out = ""
for k, v in ipairs(args) do
v = mw.text.trim(v)
if v ~= "" then
out = out .. "<li>" .. v .. "</li>"
end
end
local listclass = ""
if semi then
listclass = listclass .. "sslist"
else
listclass = listclass .. "cslist"
end
if embedded then
listclass = listclass .. " cslist-embedded"
end
if out ~= "" then
return '<ul class="'.. listclass ..'">' .. out .. '</ul>'
end
end
return p