Editing Module:Nested Lists
Appearance
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 16: | Line 16: | ||
wrapper = {'Template:Nested Lists'} | wrapper = {'Template:Nested Lists'} | ||
}) | }) | ||
return p._main(args) | return p._main(args) | ||
end | end | ||
| Line 23: | Line 24: | ||
local link = args.link == '1' | local link = args.link == '1' | ||
local iconFormat = args.icon | local iconFormat = args.icon | ||
local iconSize = args.icon_size or '25' | local iconSize = args.icon_size or '25' | ||
| Line 29: | Line 29: | ||
iconSize = mw.text.trim(tostring(iconSize)) | iconSize = mw.text.trim(tostring(iconSize)) | ||
iconSize = mw.ustring.gsub(iconSize, '[pP][xX]$', '') | iconSize = mw.ustring.gsub(iconSize, '[pP][xX]$', '') | ||
if iconSize == '' then | if iconSize == '' then | ||
iconSize = '25' | iconSize = '25' | ||
| Line 45: | Line 46: | ||
-- Determine indentation marker. | -- Determine indentation marker. | ||
local prefix = mw.ustring.sub(item, 1, 2) | local prefix = mw.ustring.sub(item, 1, 2) | ||
if levels[prefix] ~= nil then | if levels[prefix] ~= nil then | ||
marker = prefix | marker = prefix | ||
| Line 52: | Line 54: | ||
local level = levels[marker] or 0 | local level = levels[marker] or 0 | ||
-- [no] disables the icon for this item. | -- [no] disables the icon for this individual item. | ||
local noIcon = false | local noIcon = false | ||
if mw.ustring.sub(text, 1, 4) == '[no]' then | if mw.ustring.sub(text, 1, 4) == '[no]' then | ||
noIcon = true | noIcon = true | ||
text = mw.text.trim(mw.ustring.sub(text, 5)) | text = mw.text.trim(mw.ustring.sub(text, 5)) | ||
end | end | ||
-- Separate page target and display label. | -- Separate page target and display label. | ||
-- | |||
-- Example: | |||
-- Princess Peach|Peach | |||
-- | |||
-- target = Princess Peach | |||
-- label = Peach | |||
local target = text | local target = text | ||
local label = text | local label = text | ||
local separator = mw.ustring.find(text, '|', 1, true) | local separator = mw.ustring.find(text, '|', 1, true) | ||
| Line 90: | Line 89: | ||
local icon = '' | local icon = '' | ||
if not noIcon then | if iconFormat and iconFormat ~= '' and not noIcon then | ||
local iconName = | -- {item} always uses the raw page target, | ||
-- never the generated wiki link or display label. | |||
local iconName = mw.ustring.gsub( | |||
iconFormat, | |||
'{item}', | |||
function() | |||
return target | |||
end | |||
) | |||
if pageExists then | |||
icon = string.format( | |||
'[[File:%s|%spx|link=%s]]', | |||
iconName, | |||
iconSize, | |||
' | target | ||
) | |||
else | |||
icon = string.format( | |||
'[[File:%s|%spx]]', | |||
iconName, | |||
iconSize | |||
) | ) | ||
end | end | ||
end | end | ||