Module:Nested Lists: Difference between revisions

ReisuDesign (talk | contribs)
No edit summary
ReisuDesign (talk | contribs)
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 16: Line 16:
wrapper = {'Template:Nested Lists'}
wrapper = {'Template:Nested Lists'}
})
})
return p._main(args)
return p._main(args)
end
end
Line 24: Line 23:
local link = args.link == '1'
local link = args.link == '1'
local iconFormat = args.icon
local iconFormat = args.icon
local iconMain = args.icon_main == '1'
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 46: Line 45:
-- 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 54: Line 52:
local level = levels[marker] or 0
local level = levels[marker] or 0


-- [no] disables the icon for this individual item.
-- [no] disables the icon for this item.
local noIcon = false
local noIcon = false
local customIcon = nil


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))
else
-- [Icon Name.png] specifies a custom icon.
local customIconName, remainingText =
mw.ustring.match(text, '^%[([^%]]+)%]%s*(.*)$')
if customIconName then
customIcon = mw.text.trim(customIconName)
text = mw.text.trim(remainingText)
end
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 89: Line 90:
local icon = ''
local icon = ''


if iconFormat and iconFormat ~= '' and not noIcon then
if not noIcon then
-- {item} always uses the raw page target,
local iconName = customIcon
-- never the generated wiki link or display label.
 
local iconName = mw.ustring.gsub(
-- Use the global icon format unless icon_main is enabled
iconFormat,
-- and this is not a level 0 item.
'{item}',
if not iconName and iconFormat and iconFormat ~= '' and (not iconMain or level == 0) then
function()
iconName = mw.ustring.gsub(
return target
iconFormat,
'{item}',
function()
return target
end
)
end
 
if iconName and iconName ~= '' then
-- Check whether the requested icon exists.
if not exists.checkExists('File:' .. iconName) then
iconName = 'Unknown.png'
end
end
)


if pageExists then
-- Link the icon to the item page if it exists.
icon = string.format(
if pageExists then
'[[File:%s|%spx|link=%s]]',
icon = string.format(
iconName,
'[[File:%s|%spx|link=%s]]',
iconSize,
iconName,
target
iconSize,
)
target
else
)
icon = string.format(
else
'[[File:%s|%spx]]',
icon = string.format(
iconName,
'[[File:%s|%spx]]',
iconSize
iconName,
)
iconSize
)
end
end
end
end
end