Modul:Navbox: Unterschied zwischen den Versionen
update from Module:Navbox/sandbox per Template talk:Navbox#Merging nowrap navbox to implement nowrapitems=yes to nowrap listN + above + below text
(update from Module:Navbox/sandbox per talk; this implements automatic striping that applies to a navbox and any subgroup (child) navboxes it contains) |
(update from Module:Navbox/sandbox per Template talk:Navbox#Merging nowrap navbox to implement nowrapitems=yes to nowrap listN + above + below text) |
||
Zeile 57: | Zeile 57: | ||
end | end | ||
local function | local function processItem(item, nowrapitems) | ||
if | if item:sub(1, 2) == '{|' then | ||
-- Applying nowrap to lines in a table does not make sense. | |||
-- Add newlines to compensate for trim of x in |parm=x in a template. | |||
return | return '\n' .. item ..'\n' | ||
end | |||
if nowrapitems == 'yes' then | |||
local lines = {} | |||
for line in (item .. '\n'):gmatch('([^\n]*)\n') do | |||
local prefix, content = line:match('^([*:;#]+)%s*(.*)') | |||
if prefix and not content:match('^<span class="nowrap">') then | |||
line = prefix .. '<span class="nowrap">' .. content .. '</span>' | |||
end | |||
table.insert(lines, line) | |||
end | |||
item = table.concat(lines, '\n') | |||
end | |||
if item:match('^[*:;#]') then | |||
return '\n' .. item ..'\n' | |||
end | end | ||
return item | |||
end | end | ||
Zeile 139: | Zeile 154: | ||
:css('font-size', '114%') | :css('font-size', '114%') | ||
:css('margin', '0 4em') | :css('margin', '0 4em') | ||
:wikitext( | :wikitext(processItem(args.title)) | ||
end | end | ||
Zeile 164: | Zeile 179: | ||
:attr('colspan', getAboveBelowColspan()) | :attr('colspan', getAboveBelowColspan()) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.above, args.nowrapitems)) | ||
end | end | ||
Zeile 178: | Zeile 193: | ||
:attr('colspan', getAboveBelowColspan()) | :attr('colspan', getAboveBelowColspan()) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.below, args.nowrapitems)) | ||
end | end | ||
Zeile 197: | Zeile 212: | ||
:attr('rowspan', 2 * #listnums - 1) | :attr('rowspan', 2 * #listnums - 1) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.imageleft)) | ||
end | end | ||
Zeile 257: | Zeile 272: | ||
:tag('div') | :tag('div') | ||
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') | :css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') | ||
:wikitext( | :wikitext(processItem(listText, args.nowrapitems)) | ||
if index == 1 and args.image then | if index == 1 and args.image then | ||
Zeile 269: | Zeile 284: | ||
:attr('rowspan', 2 * #listnums - 1) | :attr('rowspan', 2 * #listnums - 1) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.image)) | ||
end | end | ||
end | end | ||
Zeile 325: | Zeile 340: | ||
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end | if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end | ||
for | for _, cat in ipairs(getTrackingCategories()) do | ||
builder:wikitext('[[Category:' .. cat .. ']]') | builder:wikitext('[[Category:' .. cat .. ']]') | ||
end | end | ||
Zeile 371: | Zeile 386: | ||
args = navboxArgs | args = navboxArgs | ||
for k, | for k, _ in pairs(args) do | ||
local listnum = | if type(k) == 'string' then | ||
local listnum = k:match('^list(%d+)$') | |||
if listnum then table.insert(listnums, tonumber(listnum)) end | |||
end | |||
end | end | ||
table.sort(listnums) | table.sort(listnums) |