end  
groupCell
:attr('scope', 'row')
:addClass(cfg.class.navbox_group)
:addClass(args[cfg.arg.groupclass])
:cssText(args[cfg.arg.basestyle])
-- If groupwidth not specified, minimize width
:css('width', args[cfg.arg.groupwidth] or '1%')  
groupCell
:cssText(args[cfg.arg.groupstyle])
:cssText(args[groupstyle_and_num])
:wikitext(args[group_and_num])
end  
local listCell = row:tag('td')  
if args[group_and_num] then
listCell
:addClass(cfg.class.navbox_list_with_group)
else
listCell:attr('colspan', 2)
end  
if not args[cfg.arg.groupwidth] then
listCell:css('width', '100%')
end  
local rowstyle -- usually nil so cssText(rowstyle) usually adds nothing
if index % 2 == 1 then
rowstyle = args[cfg.arg.oddstyle]
else
rowstyle = args[cfg.arg.evenstyle]
end  
local list_and_num = andnum('list', listnum)
local listText = inArray(cfg.keyword.subgroups, args[list_and_num])
and getSubgroup(args, listnum, args[list_and_num]) or args[list_and_num]  
local oddEven = cfg.marker.oddeven
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = listText:find(cfg.pattern.navbox_title) and cfg.marker.restart or cfg.class.navbox_odd_part
end  
local liststyle_and_num = andnum('liststyle', listnum)
local listclass_and_num = andnum('listclass', listnum)
listCell
:css('padding', '0')
:cssText(args[cfg.arg.liststyle])
:cssText(rowstyle)
:cssText(args[liststyle_and_num])
:addClass(cfg.class.navbox_list)
:addClass(cfg.class.navbox_part .. oddEven)
:addClass(args[cfg.arg.listclass])
:addClass(args[listclass_and_num])
:tag('div')
:css('padding',
(index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '0 0.25em'
:wikitext(processItem(listText, args[cfg.arg.nowrapitems]))  
if index == 1 and args[cfg.arg.image] then
row
:tag('td')
:addClass(cfg.class.noviewer)
:addClass(cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '') -- Minimize width
:css('padding', '0 0 0 ')
:cssText(args[cfg.arg.imagestyle])
:attr('rowspan', listnums_size)
:tag('div')
:wikitext(processItem(args[cfg.arg.image]))
end
end  
local function has_list_class(htmlclass)
local patterns = {
'^' .. htmlclass .. '$',
'%s' .. htmlclass .. '$',
'^' .. htmlclass .. '%s',
'%s' .. htmlclass .. '%s'
}  
for arg, _ in pairs(args) do
if type(arg) == 'string' and mw.ustring.find(arg, cfg.pattern.class) then
for _, pattern in ipairs(patterns) do
if mw.ustring.find(args[arg] or '', pattern) then
return true
end
end
end
end
return false
end  
-- there are a lot of list classes in the wild, so we add their TemplateStyles
local function add_list_styles
local = mw.getCurrentFrame
local function add_list_templatestyles(htmlclass, templatestyles)
if has_list_class(htmlclass) then
return :extensionTag{
name = 'templatestyles', args = { src = templatestyles }
}
else
return ''
end
end  
local hlist_styles = add_list_templatestyles('hlist', cfg.hlist_templatestyles)
local plainlist_styles = add_list_templatestyles('plainlist', cfg.plainlist_templatestyles)  
-- a second workaround for phab:T303378
-- when that issue is fixed, we can actually use has_navbar not to emit the
-- tag here if we want
if has_navbar and hlist_styles == '' then
hlist_styles = :extensionTag{
name = 'templatestyles', args = { src = cfg.hlist_templatestyles }
}
end  
-- hlist -> plainlist is best-effort to preserve old Common.css ordering.
-- this ordering is not a guarantee because most navboxes will emit only
-- one of these classes [hlist_note]
return hlist_styles .. plainlist_styles
end  
local function needsHorizontalLists
if == cfg.keyword.border_subgroup or args[cfg.arg.tracking] == cfg.keyword.tracking_no then
return false
end
return not has_list_class(cfg.pattern.hlist) and not has_list_class(cfg.pattern.plainlist)
end  
local function hasBackgroundColors
for _, key in ipairs({cfg.arg.titlestyle, cfg.arg.groupstyle,
cfg.arg.basestyle, cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('background', 1, true) then
return true
end
end
return false
end  
local function hasBorders
for _, key in ipairs({cfg.arg.groupstyle, cfg.arg.basestyle,
cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('', 1, true) then
return true
end
end
return false
end  
local function isIllegible
local styleratio = require('Module:Color contrast')._styleratio
for key, style in pairs(args) do
if tostring(key):match(cfg.pattern.style) then
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
return true
end
end
end
return false
end  
local function getTrackingCategories
local cats = {}
if needsHorizontalLists then table.insert(cats, cfg.category.horizontal_lists) end
if hasBackgroundColors then table.insert(cats, cfg.category.background_colors) end
if isIllegible then table.insert(cats, cfg.category.illegible) end
if hasBorders then table.insert(cats, cfg.category.borders) end
return cats
end  
local function renderTrackingCategories(builder, )
local title = mw.title.getCurrentTitle
if title.namespace ~= 10 then return end -- not in template space
local subpage = title.subpageText
if subpage == cfg.keyword.subpage_doc or subpage == cfg.keyword.subpage_sandbox
or subpage == cfg.keyword.subpage_testcases then return end  
for _, cat in ipairs(getTrackingCategories) do
builder:wikitext('')
end
end  
local function renderMainTable(, listnums)
local tbl = mw.html.create('table')
:addClass(cfg.class.nowraplinks)
:addClass(args[cfg.arg.bodyclass])  
local state = args[cfg.arg.state]
if args[cfg.arg.title] and state ~= cfg.keyword.state_plain and state ~= cfg.keyword.state_off then
if state == cfg.keyword.state_collapsed then
state = cfg.class.collapsed
end
tbl
:addClass(cfg.class.collapsible)
:addClass(state or cfg.class.autocollapse)
end  
tbl:css('-spacing', 0)
if == cfg.keyword.border_subgroup or == cfg.keyword.border_none then
tbl
:addClass(cfg.class.navbox_subgroup)
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
else -- regular navbox - bodystyle and style will be applied to the wrapper table
tbl
:addClass(cfg.class.navbox_inner)
:css('background', 'transparent')
:css('color', 'inherit')
end
tbl:cssText(args[cfg.arg.innerstyle])  
renderTitleRow(tbl)
renderAboveRow(tbl)
local listnums_size = #listnums
for i, listnum in ipairs(listnums) do
renderListRow(tbl, i, listnum, listnums_size)
end
renderBelowRow(tbl)  
return tbl
end  
local function add_navbox_styles(hiding_templatestyles)
local = mw.getCurrentFrame
-- This is a lambda so that it doesn't need the as a parameter
local function add_user_styles(templatestyles)
if not isblank(templatestyles) then
return :extensionTag{
name = 'templatestyles', args = { src = templatestyles }
}
end
return ''
end  
-- get templatestyles. load base from config so that Lua only needs to do
-- the work once of parser tag expansion
local base_templatestyles = cfg.templatestyles
local templatestyles = add_user_styles(args[cfg.arg.templatestyles])
local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles])  
-- The 'navbox-styles' div exists to wrap the styles to work around T200206
-- more elegantly. Instead of combinatorial rules, this ends up being linear
-- number of CSS rules.
return mw.html.create('div')
:addClass(cfg.class.navbox_styles)
:wikitext(
add_list_styles .. -- see [hlist_note] applied to 'before base_templatestyles'
base_templatestyles ..
templatestyles ..
child_templatestyles ..
table.concat(hiding_templatestyles)
:done
end  
-- work around phab:T303378
-- for each arg: find all the templatestyles strip markers, insert them into a
-- table. then remove all templatestyles markers from the arg
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)'
local argHash = 0
for k, arg in pairs(args) do
if type(arg) == 'string' then
for marker in string.gfind(arg, strip_marker_pattern) do
table.insert(hiding_templatestyles, marker)
end
argHash = argHash + #arg
args[k] = string.gsub(arg, strip_marker_pattern, '')
end