-- this has coding on the colours for green on black
local bottomBorder = tostring(branchThickness) ..'px ' .. branchState .. (branchColor~="" and ' ' .. branchColor or '')
local leftBorder = tostring(nodeThickness) ..'px ' .. nodeState .. (nodeColor~="" and ' ' .. nodeColor or '')  
--The default styles are in the CSS (styles.css)
-- the inline styling is applied when thickness, color or state are change  
local useInlineStyle = false
-- use inline styling non-default color, line thickness or state have been set
if branchColor ~= "" or branchThickness ~= 1 or branchState ~= "solid" then
useInlineStyle = true
end  
-- variables for hand bar or bracket
--local barColor = ""
local barRight = pargs['bar'..tostring(childNumber)] or "0"
local barBottom = pargs['barend'..tostring(childNumber)] or "0"
local barTop = pargs['barbegin'..tostring(childNumber)] or "0"
local barLabel = pargs['barlabel'..tostring(childNumber)] or ""
local groupLabel = pargs['grouplabel'..tostring(childNumber)] or ""
local groupLabelStyle = pargs['grouplabelstyle'..tostring(childNumber)] or ""
local labelStyle = pargs['labelstyle'..tostring(childNumber)] or ""
local sublabelStyle = pargs['sublabelstyle'..tostring(childNumber)] or ""  
--replace colours with format string; need bar for all three options
if barRight ~= "0" then barRight = " solid " .. barRight end
if barTop ~= "0" then barRight = " solid " .. barTop end
if barBottom ~= "0" then barRight = " solid " .. barBottom end
if barTop ~= "0" then barTop = " solid " .. barTop end
if barBottom ~= "0" then barBottom = " solid " .. barBottom end  
-- now construct wikitext
local cladeString = ''
local styleString = ''
local border -- will be used if color, thickness or state is to be changed
local classString = ''
local reverse
local width  
-- class to add if using reverse (rtl) cladogram;
if reverseClade then reverse end  
-- (1) wikitext for new row
--cladeString = cladeString .. '\n|-'  
-- (2) now add cell with label  
if useInlineStyle then
if childNumber == 1 then
border .. bottomBorder .. ';'
--border .. bottomBorder .. ';'
else -- for 2-17
if reverseClade then
border .. leftBorder .. ';-bottom:' .. bottomBorder .. ';'
else
border .. leftBorder .. ';-bottom:' .. bottomBorder .. ';'
end
end
end  
if useInlineStyle or branchStyle ~= '' or branchLength ~= "" or labelStyle ~= "" then
local branchLength
if branchLength ~= "" then
if childNumber == 1 then
branchLength .. branchLength .. ';' -- add width to first element
end
--if childNumber > 1 then prefix = 'max-' end
branchLengthStyle = branchLengthStyle --= prefix .. 'width:' .. branchLength .. ';'
.. 'max-width:' .. branchLength ..';'
.. 'padding:0em;' -- remove padding to make calculation easier
-- following moved to styles.css
-- .. 'white-space:nowrap'
-- .. 'overflow:hidden;' -- clip labels longer than the max-width
-- .. 'text-overflow:clip;' -- ellipsis;'
width
end
styleString = ''
end  
if childNumber == 1 then
classString= ' ' -- add class "first" for top row
else
classString = ' ' -- add "reverse" class if ltr cladogram
end  
-- wikitext for cell with label
local labelCellString = '\n|' .. classString .. styleString .. '|' .. p.addLabel(childNumber,nodeLabel) -- p.addLabel(nodeLabel)  
--cladeString = cladeString .. labelCellString  
---
-- (3) add cell with leaf (which may be a table with transluded clade content)  
if barRight ~= "0" then
if reverseClade then -- we want the bar on the
styleString = ''
else
styleString = ''
end
else
if (branchStyle ~= '') then
styleString = ''
else
styleString = '' -- use defaults in styles.css
end
end  
classString = ''  
--note: the \n causes plain leaf elements get wrapped in <p> with
this adds spacing to rows, but is set by defaults rather than the clade template
it also means there are two newlines when it is a clade structure (which might explain some past issues)  
local content = '\n' .. nodeLeaf -- the newline is not necessary, but keep for backward compatibility  
-- test using image parameter
local image = pargs['image'..tostring(childNumber)] or ""  
if image ~= "" then
--content = content .. image -- basic version
content = '\n{|class=clade style=width:auto' --defaults to width:100% because of class "clade"
.. '\n|class=clade-leaf|\n' .. nodeLeaf
.. '\n|class=clade-leaf|\n' .. image
.. '\n|}'
-- note: the classes interfere with the node counter, so try simpler version with style
content = '\n{|style=width:100%;-spacing:0' --width:auto is "tight"; 100% needed for image alignment
.. '\n|style=:0;padding:0|\n' .. nodeLeaf
.. '\n|style=:0;padding:0|\n' .. image
.. '\n|}'
end  
-- wikitext for leaf cell (note: nodeLeaf needs to be on newline if new wikitable)
-- but that is no longer the case (newline is now forced)
-- the newline wraps plain leaf terminals in <P> with vertical padding (see above)  
--local leafCellString = '\n|rowspan=2 ' .. classString .. styleString .. ' |\n' .. content -- the new line causes <p> wrapping for plain leaf terminals
local leafCellString = '\n|rowspan=2 ' .. classString .. styleString .. ' |' .. content  
--cladeString = cladeString .. leafCellString  
---
-- (4) stuff for -hand bracket labels  
classString=''  
local barLabelCellString = ''
if barRight ~= "0" and barLabel ~= "" then
barLabelCellString = '\n|rowspan=2 ' .. classString .. ' |' .. barLabel
else -- uncomment following line to see the cell structure
--barLabelCellString = '\n|rowspan=2 ' .. classString .. ' |' .. 'BL'
end  
if groupLabel ~= "" then
barLabelCellString = barLabelCellString .. '\n|rowspan=2 ' .. classString .. ' |' .. groupLabel
else -- uncomment following line to see the cell structure
--barLabelCellString = barLabelCellString .. '\n|rowspan=2 ' .. classString .. '" |' .. 'GL'
end  
--cladeString = cladeString .. barLabelCellString  
---
-- (5) add second row (only one cell needed for sublabel because of rowspan=2);
-- note: earlier versions applied branch style to row rather than cell
-- for consistency, it is applied to the sublabel cell as with the label cell  
--cladeString = cladeString .. '\n|-'  
---
-- (6) add cell containing sublabel  
local subLabel = pargs['sublabel'..tostring(childNumber)] or "" -- request in addLabel  
-- FOR TESTING: use subLabel for annotating the clade structues to use structure information (DEBUGGIING ONLY)
--if childNumber==lastNode then subLabel= infoOutput end
-- END TESTING  
border
styleString = ''
if useInlineStyle then
if childNumber==lastNode then -- if childNumber==lastNode we don't want , otherwise we do
border
else
if reverseClade then
border .. leftBorder .. ';'
else
border .. leftBorder .. ';'
end
end
end
if borderStyle ~= * or branchStyle ~= * or branchLength ~= '' or sublabelStyle ~= "" then
local branchLength
if branchLength ~= "" then
if childNumber == 1 then
branchLength .. branchLength .. ';' -- add width to first element
end
--if childNumber > 1 then prefix = 'max-' end
branchLengthStyle = branchLengthStyle --= prefix .. 'width:' .. branchLength .. ';'
.. 'max-width:' .. branchLength ..';'
.. 'padding:0em;' -- remove padding to make calculation easier
end
styleString = ''
--styleString = ''
end  
--local sublabel = p.addLabel(childNumber,subLabel)  
if childNumber == lastNode then
classString = ' '
else
classString = ' '
end
local sublabelCellString = '\n|' .. classString .. styleString .. '|' .. p.addLabel(childNumber,subLabel)  
--cladeString = cladeString .. sublabelCellString  
-- constuct child element wikitext
if reverseClade then
cladeString = cladeString .. '\n|-'
cladeString = cladeString .. barLabelCellString
cladeString = cladeString .. leafCellString
cladeString = cladeString .. labelCellString
cladeString = cladeString .. '\n|-'
cladeString = cladeString .. sublabelCellString
else
cladeString = cladeString .. '\n|-'
cladeString = cladeString .. labelCellString
cladeString = cladeString .. leafCellString
cladeString = cladeString .. barLabelCellString