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 | ||
-- | -- 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. | ||
local target = text | local target = text | ||
local label = text | local label = text | ||
| Line 89: | Line 95: | ||
local icon = '' | local icon = '' | ||
if | if not noIcon then | ||
local iconName = customIcon | |||
local iconName = | |||
if | -- If there is no custom icon, use the global format. | ||
if not iconName and iconFormat and iconFormat ~= '' then | |||
iconName = mw.ustring.gsub( | |||
iconFormat, | |||
'{item}', | |||
function() | |||
return target | |||
end | |||
) | ) | ||
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 | ||