for x, y in ipairs(nodeFunc.pattern) do
if nodeFunc.skipAllowed[y] then
nodeFunc.called[y] = nodeFunc[y].main(x)
end
end
end
local canvas = nodeFunc.pattern and nodeFunc.called.canvas and 6
rowNum[m.r + (canvas or 0)]:tag'td':attr{rowspan = maxSpan((canvas and 0 or 6) + bump * 2, m.r + (canvas or 0), rows), colspan = p.colspan}
elseif m.phase == 2 then
if nodeFunc.pattern and (nodeFunc.called.bridge or nodeFunc.called.canvas) then
step = step + 1
end
m.num = m.num + 1
step = step + (p.omit_blanks and 0 or m.showBox)
bumps = bumps + (col.show3rd and 0 or maxSpan(p.span, m.r, rows))
end
elseif m.phase == 0 then
if nodeFunc.pattern then
for x, y in ipairs(nodeFunc.pattern) do
if nodeFunc[y] and nodeFunc[y].main then
nodeFunc.called[y] = nodeFunc[y].main(x)
end
end
if m.available == false then
m.showBox = nodeArgs.blank
step = step + 1
end
end
if m.showBox[1] then
if col.show3rd then
col.show3rd = (m.num - col.top) * 2
if col.show3rd == 2 then
if p.textThird:match('omit_label') then
p.textThird = nil
end
if rowNum[rows + 1] and p.cols > 1 then --if 3rd place extends below bottom cell
rowNum[rows + 1]:tag'td':attr{
rowspan = m.r + 9 - rows - (text and 0 or 2),
colspan = (p.cols - 1) * 4
}
end
if p.tCols == 1 then
bumps = p.textThird and 3 or 0
elseif p.branch_upwards then
r = 7
bumps = p.textThird and 2 or 0
end
m.r = r + bumps
if p.textThird then
drawHead(p.textThird, m.r)
bumps = bumps + 2
m.r = r + bumps
end
end
end
dpBox(nodeFunc.pattern and nodeFunc.nonFunc or args[step], m.r, skipMatch[m.num])
if p.previewnumbers then
p.namespace = p.namespace or mw.title.getCurrentTitle.namespace
if p.namespace ~= 0 then
tab.r:tag'div'
:css{
float = '',
= ' solid red',
padding = '0 .5ex',
['color'] = 'red'
}
:wikitext(m.num)
:attr{title = 'Number only visible outside article space (e.g. template) when |numberpreview=yes'}
end
end
end
if p.colspan then
m.nonEmpty = {}
for s = step + 2, step + nodeArgs.team.offset do
local i = {s, s + nodeArgs.team.offset}
if args[i[1]] or args[i[2]] then
table.insert(m.nonEmpty, i)
end
end
if p.bold and m.showBox[2] and m.showBox[3] and not unBold[m.num] then
m.bold = {
box = {},
clean = {}
}
local notSummed = not p.scoreSumBox or #m.nonEmpty < 2
for s, i in ipairs(m.nonEmpty) do
m.bold.clean[s] = {p.scoreWasher:main(args[i[1]]), p.scoreWasher:main(args[i[2]])}
m.bold.box[s] = notSummed and boldWin(m.bold.clean[s][1], m.bold.clean[s][2]) or callableEmpty
end
if p.scoreSumBox and m.nonEmpty[2] then
local i = {-step, -step - 1}
table.insert(m.nonEmpty, i)
args[i[1]], args[i[2]] = p.scoreWasher.sum(m.bold.clean)
m.bold.box[p.scoreBoxes] = boldWin(args[i[1]], args[i[2]])
end
getmetatable(boxStyle).__index = p.scoreSumBoxes and {[#m.nonEmpty] = boxStyle[p.scoreBoxes]}
m.bold.win = m.bold.box[#m.nonEmpty] or callableEmpty
else
m.bold = infiniteEmpty
end
end
else
if m.showBox[m.phase] then
p.teamBoxCSS = colorFinal and
{ = p.teamBoxNormal., background = p.bgColor[m.phase + (col.show3rd or 0)]}
or p.teamBoxNormal
local f = {phase = m.phase, bold = m.bold.win(m.phase)}
teamBox(args[step + nodeArgs.team[m.phase]], m.r, f)
f[1] = ''
if p.colspan then
if m.nonEmpty[1] then
local loneSum
if #m.nonEmpty < p.scoreBoxes then
loneSum = #m.nonEmpty == 1 and boxStyle[p.scoreBoxes]
tab.r:attr{colspan = 1 + p.scoreBoxes - #m.nonEmpty}
end
for s, i in ipairs(m.nonEmpty) do
f.borderLeft = boxStyle(s)
f.sumBox = loneSum or boxStyle[s]
f.bold = m.bold.box[s](m.phase)
teamBox(args[i[m.phase]], m.r, f)
end
else
for s = 1, p.scoreBoxes do
f.borderLeft = boxStyle(s)
teamBox(nil, m.r, f)
end
end
end
end
if m.phase == 2 then
col.show3rd = col.show3rd ~= 2 and col.show3rd or nil
if p.scoreWasher.demo and p.scoreWasher.demo == m.num and mw.title.getCurrentTitle.namespace ~= 0 then
table.insert(m.bold.clean, 1, {args[step + nodeArgs.team[1]], args[step + nodeArgs.team[2]]})
return table.concat{
'Score data for match specified by <code>|demoWash=</code>:
',
mw.dumpObject{scores = m.bold.clean, cycles = p.scoreWasher.cycles, sum = p.scoreSumBox and {m.nonEmpty[#m.nonEmpty][1], m.nonEmpty[#m.nonEmpty][1]}},
'<table>',
tostring(sp.row), '<tr>',
tostring(rowNum[m.r - 4]), '<tr>',
tostring(rowNum[m.r - 2]), '<tr>',
tostring(rowNum[m.r]), '</table>',
}
end
if nodeFunc.orphan.num == m.num then
skipMatch[m.num] = 'orphan'
end
step = step + m.showBox
m.num = m.num + 1
if bump > 0 and rowNum[m.r + 2] and not (nodeFunc.pattern and nodeFunc.called.canvas) then
bumps = bumps + p.span
rowNum[m.r + 2]:node(bumpMid)
end
r = r + (col.show3rd or bump)
end
end
m.phase = (m.phase + 1) % 3
end
end
if p.cols > c then--draw lines to next round
p.unit = bump + 3
bump = 3 * math.pow(2, c) - 3
bumps = p.branch_upwards and 4 or (p.unit + 1)
rowNum[1]
:tag'td':attr{rowspan = bumps}
if not p.branch_upwards then
rowNum[1]:tag'td'
:attr{rowspan = (p.branch_upwards or bump) + 4}
:css(nodeFunc.bridge.lay[c](0) and
{['-'] = p.reuseStr.solid}
or {}
end
col.n = 0
for r = bumps + 1, rows, p.unit * 2 do
tab.r = rowNum[r]:tag'td'
local interval = ((r - bumps - 1) / (p.unit * 2)) % 4
if interval % 2 == 0 then
--col.t and col.t2 control whether lines are drawn
col.t = col.t2 or skipMatch[col.tot + col.n / 2 + 1] and 3 or ((skipMatch[col.top] and 1 or 0) + (skipMatch[col.top + 1] and 2 or 0))
col.n = col.n + 2
col.t2 = skipMatch[col.tot + col.n / 2 + 1] and 3 or ((skipMatch[col.top + col.n] and 1 or 0) + (skipMatch[col.top + col.n + 1] and 2 or 0))
if col.t == 0 then
tab.r
:attr{rowspan = maxSpan(p.unit * 2, r, rows)}
:css(skipMatch[col.tot + col.n / 2] and {} or {
= p.reuseStr.solid,
['-'] = 0
})
else
tab.r
:attr{rowspan = maxSpan(p.unit, r, rows)}
:cssText(col.t == 2 and
p:saveStr('topRight', '-width:', tab.line[2], ' 0 0;-style:solid')
or col.t == 1 and (nodeFunc.bridge.lay[c](col.n - 2) and
p:saveStr('', ';-:', p.reuseStr.solid)
or 'vertical-align:bottom'
or nil
:node(col.t == 1 and interval > 0 and not nodeFunc.bridge.lay[c](col.n - 2) and p.cornerDiv)
rowNum[r + (p.branch_upwards and (4 - bump) or p.unit)]:tag'td'
:attr{rowspan = maxSpan(p.unit, r + p.unit, rows)}
:cssText(col.t == 1 and
p:saveStr('bttmRght', '-width:0 ', tab.line[2], ' 0;-style:solid')
or col.t == 2 and (nodeFunc.bridge.lay[c](col.n + 2) and
p:saveStr('', ';-:', p.reuseStr.solid)
or 'vertical-align:top'
or nil
:node(col.t == 2 and interval ~= 2 and not nodeFunc.bridge.lay[c](col.n + 2) and p.cornerDiv)
end
col.t = {
col.t < 3,
rowNum[r + p.unit * 5] and col.t2 < 3 or false
}
rowNum[r + (p.branch_upwards or p.unit)]:tag'td'
:attr{rowspan = maxSpan(p.unit * 4, r + (p.branch_upwards and (4 - bump) or p.unit), rows)}
:css(interval == 0 and (col.t[1] or col.t[2]) and {
['-width'] = table.concat{tab.line[1][col.t[1]], ' 0 ', tab.line[1][col.t[2]]},
['-style'] = 'solid'
} or {})
else
tab.r
:attr{rowspan = maxSpan(p.unit * 2, r, rows)}
:css(nodeFunc.bridge.lay[c](col.n) and
{['-'] = p.reuseStr.solid}
or {}
end
end
end
end
local lock_height = (head_br.count or 0) + 1
return args.scroll_height and
mw.html.create'div'
:cssText'-bottom: solid #eee;display:inline-block'
:node(not (p.scroll_head_unlock or p.no_column_head) and mw.html.create'div'
:css{
overflow = 'hidden',
height = lock_height * 1.4 + 1.6 .. 'em',
['-bottom'] = 'inherit',
['margin-'] = ''
}
:node(mw.clone(tab))
:tag'div'
:css{
['overflow-y'] = 'scroll',
['max-height'] = tonumber(args.scroll_height, 10) and args.scroll_height .. 'px' or args.scroll_height
}
:node(not (p.scroll_head_unlock or p.no_column_head) and
tab:css{['margin-top'] = math.floor(-10 * (lock_height * 1.4 + 1.6)/(fontSize or .9)) / 10 .. 'em', ['padding-top'] = '-'}
or tab
:done
or tab
end  
--local standard = {
'beta' = {
bold_winner = 'high',
omit_blanks = 'yes',
auto_3rd = 'yes'
}
}--
function p.main(, columns)
local args = require'Module:Arguments'.getArgs(, {trim = false})
args.columns = args.columns or columns
return p._main(args)
end  
function p.seed
local parent = :getParent or
function arg(k, alt)
return parent.args[k] or .args[k] or alt
end