Editing Module:Nested Lists
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' | ||
local output = {} | local output = {} | ||
| Line 45: | Line 38: | ||
-- 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] | |||
if levels[prefix] then | |||
marker = prefix | marker = prefix | ||
text = mw.text.trim(mw.ustring.sub(item, 3)) | text = mw.text.trim(mw.ustring.sub(item, 3)) | ||
| Line 52: | Line 46: | ||
local level = levels[marker] or 0 | local level = levels[marker] or 0 | ||
-- [no] | -- Check for [no] icon override. | ||
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 | ||
-- | -- The raw item text is kept separately. | ||
local | local itemText = text | ||
-- Check whether the page exists. | |||
-- Check whether the | |||
local pageExists = false | local pageExists = false | ||
if link | if link then | ||
pageExists = exists.checkExists( | pageExists = exists.checkExists(itemText) | ||
end | end | ||
| Line 90: | Line 67: | ||
local icon = '' | local icon = '' | ||
if not noIcon then | if iconFormat and iconFormat ~= '' and not noIcon then | ||
local iconName = | local iconName = mw.text.gsub( | ||
iconFormat, | |||
'{item}', | |||
itemText | |||
) | |||
if pageExists then | |||
icon = string.format( | |||
'[[File:%s|%spx|link=%s]]', | |||
iconName, | |||
iconSize, | |||
' | itemText | ||
) | |||
else | |||
icon = string.format( | |||
'[[File:%s|%spx]]', | |||
iconName, | |||
iconSize | |||
) | ) | ||
end | end | ||
end | end | ||
-- Generate the text. | -- Generate the text link. | ||
local displayText = | local displayText = itemText | ||
if pageExists then | if pageExists then | ||
displayText = '[[' .. | displayText = '[[' .. itemText .. ']]' | ||
end | end | ||
-- | -- Add icon and text. | ||
local content = displayText | local content = displayText | ||