Editing Module:Nested Lists

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
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 iconMain = args.icon_main == '1'
local iconSize = args.icon_size or '25'
local iconSize = args.icon_size or '25'
-- Allow icon_size to be written as either 25 or 25px.
iconSize = mw.text.trim(tostring(iconSize))
iconSize = mw.ustring.gsub(iconSize, '[pP][xX]$', '')
if iconSize == '' then
iconSize = '25'
end


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] ~= nil then
if levels[prefix] ~= nil then
marker = prefix
marker = prefix
Line 52: Line 46:
local level = levels[marker] or 0
local level = levels[marker] or 0


-- [no] disables the icon for this item.
-- Check for [no] icon override.
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.
-- The raw item text is kept separately.
local target = text
local itemText = text
local label = text
local separator = mw.ustring.find(text, '|', 1, true)


if separator then
-- Check whether the page exists.
target = mw.text.trim(mw.ustring.sub(text, 1, separator - 1))
label = mw.text.trim(mw.ustring.sub(text, separator + 1))
end
 
-- Check whether the target page exists.
local pageExists = false
local pageExists = false


if link and target ~= '' then
if link then
pageExists = exists.checkExists(target)
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 = customIcon
local iconName = string.gsub(
iconFormat,
'{item}',
itemText
)


-- Use the global icon format unless icon_main is enabled
if pageExists then
-- and this is not a level 0 item.
icon = string.format(
if not iconName and iconFormat and iconFormat ~= '' and (not iconMain or level == 0) then
'[[File:%s|%spx|link=%s]]',
iconName = mw.ustring.gsub(
iconName,
iconFormat,
iconSize,
'{item}',
itemText
function()
)
return target
else
end
icon = string.format(
'[[File:%s|%spx]]',
iconName,
iconSize
)
)
end
if iconName and iconName ~= '' then
-- Check whether the requested icon exists.
if not exists.checkExists('File:' .. iconName) then
iconName = 'Unknown.png'
end
-- Link the icon to the item page if it exists.
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


-- Generate the text.
-- Generate the text link.
local displayText = label
local displayText = itemText


if pageExists then
if pageExists then
displayText = '[[' .. target .. '|' .. label .. ']]'
displayText = '[[' .. itemText .. ']]'
end
end


-- Combine icon and text.
-- Add icon and text.
local content = displayText
local content = displayText


Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;