if args['dsv'] then
row
:tag('th')
:wikitext('கட்சி')
:attr('scope', 'col')
:attr('colspan', 2)
:attr('rowspan', rowspan)
:done
cols = cols + 2
row
:tag('th')
:wikitext(args.candtitle or 'வேட்பாளர்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
elseif headings['cand'] then
if headings['cand'] and headings['party'] and headings['alliance'] then
row
:tag('th')
:wikitext('வேட்பாளர்')
:attr('rowspan', rowspan)
:attr('colspan', 2)
row
:tag('th')
:wikitext(args.partytitle or 'கட்சி அல்லது கூட்டணி')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:attr('colspan', 3)
:done
cols = cols + 5
elseif headings['cand'] and headings['party'] then
row
:tag('th')
:wikitext('வேட்பாளர்')
:attr('scope', 'col')
:attr('colspan', 2)
:attr('rowspan', rowspan)
:done
cols = cols + 2
end
if headings['cand'] and not headings['party'] then
row
:tag('th')
:wikitext('வேட்பாளர்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
if headings['vp'] then
row
:tag('th')
:wikitext('Running mate')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
if headings['party'] and not headings['alliance'] then
row
:tag('th')
:wikitext(args.partytitle or 'கட்சி')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
elseif headings['party'] and headings['alliance'] then
row
:tag('th')
:wikitext(args.partytitle or 'கட்சி அல்லது கூட்டணி')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:attr('colspan', 4)
:done
cols = cols + 4
else
row
:tag('th')
:wikitext(args.partytitle or 'கட்சி')
:attr('scope', 'col')
:attr('colspan', 2)
:attr('rowspan', rowspan)
:done
cols = cols + 2
end
if rounds > 1 then
if has_seats and headings['sw'] then
row
:tag('th')
:wikitext(args.firstround or 'முதற் சுற்று')
:attr('scope', 'col')
:attr('colspan', 4)
:done
:tag('th')
:wikitext(args.secondround or 'இரண்டாம் சுற்று')
:attr('scope', 'col')
:attr('colspan', 4)
:done
elseif has_seats then
row
:tag('th')
:wikitext(args.firstround or 'முதற் சுற்று')
:attr('scope', 'col')
:attr('colspan', 3)
:done
:tag('th')
:wikitext(args.secondround or 'Second round')
:attr('scope', 'col')
:attr('colspan', 3)
:done
elseif has_votes then
row
:tag('th')
:wikitext(args.firstround or 'First round')
:attr('scope', 'col')
:attr('colspan', 2)
:done
:tag('th')
:wikitext(args.secondround or 'Second round')
:attr('scope', 'col')
:attr('colspan', 2)
:done
end
secondrow = args['embed'] and mw.html.create('') or root:tag('tr')
else
secondrow = row
end
rowspan = (rounds > 1) and 1 or (rounds < 2 and headings['st1t']) and 2 or nil
if has_seats and headings['sw'] then
for k=1, rounds do
secondrow
:tag('th')
:wikitext(args.votestitle or 'வாக்குகள்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
:tag('th')
:wikitext('+/–')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
:tag('th')
:wikitext(args.seatstitle or 'இருக்கைகள்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 4
end
end
if has_seats and not headings['sw'] then
for k=1, rounds do
secondrow
:tag('th')
:wikitext(args.votestitle or 'வாக்குகள்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
:tag('th')
:wikitext(args.seatstitle or 'இருக்கைகள்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 3
end
end
if has_votes and not has_seats then
for k=1, rounds do
secondrow
:tag('th')
:wikitext(args.votestitle or 'வாக்குகள்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
:tag('th')
:wikitext('%')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 2
end
end
if headings['sw'] and not has_seats then
row
:tag('th')
:wikitext('+/–')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
rowspan = (rounds > 1) and 2 or headings['sc'] and headings['st1t'] and 2 or nil
if headings['seats'] and not has_seats then
row
:tag('th')
:wikitext(args.seatstitle or 'இருக்கைகள்')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
if headings['st1t'] then
row
:tag('th')
:wikitext('இருக்கைகள்')
:attr('colspan', 5)
:attr('scope', 'col')
:done
if rounds < 2 then secondrow = root:tag('tr')
end
secondrow
:tag('th')
:wikitext(args.seattype1)
:attr('scope', 'col')
:done
cols = cols + 1
if headings['st2t'] then
secondrow
:tag('th')
:wikitext(args.seattype2)
:attr('scope', 'col')
:done
cols = cols + 1
end
if headings['st3t'] then
secondrow
:tag('th')
:wikitext(args.seattype3)
:attr('scope', 'col')
:done
cols = cols + 1
end
if headings['st4t'] then
secondrow
:tag('th')
:wikitext(args.seattype4)
:attr('scope', 'col')
:done
cols = cols + 1
end
if headings['st5t'] then
secondrow
:tag('th')
:wikitext(args.seattype5)
:attr('scope', 'col')
:done
cols = cols + 1
end
end
if headings['totseats'] then
row
:tag('th')
:wikitext(headings['totseats'] and 'Total
seats' or 'Totseats&pm;')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
if headings['sc'] then
row
:tag('th')
:wikitext(args.sctitle or '+/–')
:attr('scope', 'col')
:attr('rowspan', rowspan)
:done
cols = cols + 1
end
if topcell then
topcell:attr('colspan', cols)
end  
local cs = cols - 2*rounds
- (headings['sw'] and 1 or 0)
- (headings['totseats'] and 1 or 0)
- (headings['seats'] and 1 or 0)
- (headings['sc'] and 1 or 0)
- (headings['st1t'] and 1 or 0)
- (headings['st2t'] and 1 or 0)
- (headings['st3t'] and 1 or 0)
- (headings['st4t'] and 1 or 0)
- (headings['st5t'] and 1 or 0)
- (has_seats and 1 or 0)
- (has_sw and 1 or 0)
+ (has_votes and 0 or 2)
- (seats_only and 2 or 0)
local rsuff = (rounds > 1) and {*, '_2'} or {*}
for i, v in ipairs(index) do
row = root:tag('tr')
:addClass(args['class' .. v])
:css('font-weight', args['font-weight' .. v])  
-- determine the colors
local color = get_color(args['colour' .. v] or args['color' .. v] or nil, args['party' .. v])
local acolor = get_color(args['acolour' .. v] or args['acolor' .. v] or nil, args['alliance' .. v])  
-- headers
if args['header' .. v] then
row
:tag('th')
:wikitext(args['header' .. v])
:attr('colspan', cols)
else
if args['row' .. v] or headings['cand'] and not headings['party'] and not args['vp' .. v] then
row
:css('background-color', args['acolor' .. v])
:tag('td')
:wikitext(args['row' .. v] or args['cand' .. v])
:attr('colspan', cs)
elseif headings['cand'] and not headings['party'] and headings['vp'] then
row
:tag('td')
:wikitext(args['cand' .. v])
row
:tag('td')
:wikitext(args['vp' .. v])
elseif args['alliance' .. v] and args['party' .. v] and args['cand' .. v] then
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:css('background-color', acolor)
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:wikitext(args['cand' .. v])
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:wikitext(args['alliance' .. v])
row
:tag('td')
:css('background-color', color)
row
:tag('td')
:wikitext(args['party' .. v])
elseif args['alliance' .. v] and args['party' .. v] then
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:css('background-color', acolor)
row
:tag('td')
:attr('rowspan', args['aspan' .. v])
:wikitext(args['alliance' .. v])
row
:tag('td')
:css('background-color', color)
row
:tag('td')
:wikitext(args['party' .. v])
elseif args['alliance' .. v] and args['cand' .. v] then
row
:tag('td')
:css('background-color', acolor)
row
:tag('td')
:wikitext(args['cand' .. v])
row
:tag('td')
:attr('colspan', '3')
:wikitext(args['alliance' .. v])
elseif args['alliance' .. v] then
row
:tag('td')
:css('background-color', acolor)
row
:tag('td')
:attr('colspan', '3')
:wikitext(args['alliance' .. v])
elseif args['atotal' .. v] or args['atotalnv' .. v] then
row
:css('font-style', 'italic')
:tag('td')
:attr('colspan', '2')
:wikitext('மொத்தம்')
else
-- create the empty color cell
row
:css('background-color', args['acolor' .. v])
:tag('td')
:css('background-color', color)
:css('width', '')
-- add the rest of the row
if args['dsv'] then
row
:tag('td')