Module:Nested Lists: Difference between revisions

ReisuDesign (talk | contribs)
No edit summary
ReisuDesign (talk | contribs)
No edit summary
Line 54: Line 54:
local level = levels[marker] or 0
local level = levels[marker] or 0


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


-- [no] disables the icon.
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))
-- [Icon Name.png] specifies a custom icon.
else
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
Line 89: Line 95:
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(
iconFormat,
'{item}',
function()
return target
end
)


if pageExists then
-- If there is no custom icon, use the global format.
icon = string.format(
if not iconName and iconFormat and iconFormat ~= '' then
'[[File:%s|%spx|link=%s]]',
iconName = mw.ustring.gsub(
iconName,
iconFormat,
iconSize,
'{item}',
target
function()
)
return target
else
end
icon = string.format(
'[[File:%s|%spx]]',
iconName,
iconSize
)
)
end
if iconName and iconName ~= '' then
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
end