Module:Tableau Coupe

Cette page fait l’objet d’une mesure de semi-protection étendue.
Une page de Wikipédia, l'encyclopédie libre.

 Documentation[voir] [modifier] [historique] [purger]

Utilisation

Fonctions exportables :

  • abr(frame) – abréviation et abréviations discrètes, principalement pour usage interne au module. Paramètres : 1 - abréviation, 2 - texte complet, 3 - code de langue, abrd - true pour une abréviation discrète, false pour une abréviation normale
  • Tableau2(frame) – tableau à 2 joueurs/équipes.
  • Tableau4(frame) – tableau à 4 joueurs/équipes.
  • Tableau8(frame) – tableau à 2 joueurs/équipes.
  • Tableau16(frame) – tableau à 2 joueurs/équipes.
  • Tableau32(frame) – tableau à 2 joueurs/équipes.

Paramètres

Toutes les fonctions Tableau99 utilise les arguments suivant :

  • nSet : nombre de Sets / manches / scores maximal pour chaque rencontre. Pour deux sets gagnant il faut définir nSet = 3. Les fonctions ont été testées avec nSet = 3 et nSet = 5. Cela devrait aussi marcher avec d'autre valeurs.
  • sport : détermine les fonctions utilisé pour déterminé le gagnant d'un match. Seul le tennis est réellement pris en compte pour le moment, mais l'adaptation pour d'autre règles devrait être assez simple.

le Tableau 16 accepte aussi le paramètre

  • compact : permet d'avoir moins d'espacement vertical entre les résultats.

Les modèles appelant les modules tableau peuvent avoir :

  • Pour chaque match les paramètres non nommé suivant :
    • un paramètre joueur ou équipe 1
    • nSet paramètres score (éventuellement vide) de ce joueur / cette équipe 1
    • un paramètre joueur ou équipe 2
    • nSet paramètres score (éventuellement vide) de ce joueur / cette équipe 2
    • Lorsque nSet = 3, les matchs du dernier tour peuvent être défini sur 5 sets. Dès que les paramètre sont présents (même vides) les cellules nécessaires sont affichées.
  • Les matchs sont entrés par tour, du premier à la finale.
  • les match du premier tour dont les deux noms de joueur sont vides ne sont pas affichés.
  • les paramètres nommés suivant :
    • couleur-titre : la couleur de fond des titres de chaque tour. nom de couleur HTML ou un nombre hexadécimal à 6 chiffres, avec ou sans le caractère « # » (optionnel, par défaut #CFCFCF )
    • DF-titre : le titre du dernier tour. (optionnel, par défaut Finale)
    • DF1 : renseignement indiqué juste avant le score du joueur 1 du dernier tour, comme le numéro de tête de série, l'indication de joueur qualifié...
    • DF2 : idem pour le deuxième joueur du dernier tour
    • DD-titre : le titre de l'avant-dernier tour (optionnel, par défaut 1/2 finale ou suivant la valeur de DF-titre 1/4 de finale, 1/8 de finale, 3e ou 4e tour).
    • DD1 à DD4 : renseignement pour les joueur 1 à 4 de l'avant dernier tour
    • DQ-titre, DH-titre, DS-titre : titre des tours précédents (optionel, par défaut 1/4 de finale, 1/8 de finale, {{1er]] tour)
    • DQ1 à DQ8, DH1 à DH1, DS1 à DS32 : renseignement sur les 8, 16, 32 joueurs des tours précédents
  • Si nSet = 3 ou 5, tous les tableaux (à par le Tableau2) acceptent un match supplémentaire, parfois appelé « petite finale », affiché en bas à droite, sous la finale.
    • Les paramètres non nommés de résultat se place après ceux de la finale.
    • DP-titre : titre de ce match supplémentaire (optionnel, par défaut Match pour la troisième place)
    • DP1 et DP2 : renseignement sur les joueur de ce match
    • DF 3 sets = oui : lorsque nSet = 3, pour que la finale soit affiché sur 3 sets et la « grande finale » soit affiché sur 5 sets s'il y a suffisamment de paramètres défini, par exemple Championnat national de tennis des États-Unis 1891 (optionnel, par défaut c'est la Finale qui sera affichée en 5 Sets et le Match pour la troisième place qui sera en 3 sets, par exemple Simple messieurs de tennis aux Jeux olympiques d'été de 2004)
-- Le nom des variables est en anglais pour ne pas avoir d'accent et pour faciliter une éventuelle utilisation sur d'autres wiki.

local z = {}
require( 'strict' )

-- fonction abréviation, abréviation discrète
-- paramètres : 1 = abréviation, 2 = texte, 3 = langue, abrd = abréviation discrète
function z.abr (frame)
	local args = frame.args or frame or { }  -- appel direct ou via modèle
	if args[2] == nil then 
		return args[1] or ''                 -- retoune l'abréviation ou au minimum une chaine vide s'il n'y a pas de texte
	end

	local wikiText = { '<abbr' }
	if args.abrd then
		table.insert(wikiText, ' class="abbr"')
	end
	table.insert(wikiText, ' title="' .. args[2])
	if args[3] then 
		table.insert(wikiText, '" lang="' .. args[3])
	end
	table.insert(wikiText, '">' .. args[1] .. '</abbr>')

	return table.concat (wikiText)
end

-- Pattern de détection et remplacement
local retiredPattern = '^%s*(%d*)%s*<?(s?u?p?>?)ab%.?<?/?%2%s*$'    -- détection abandon
local retiredRepl = '%1<sup><abbr title="abandon">ab.</abbr></sup>' -- remplacement abandon
local disqualPattern = '^%s*(%d*)%s*<?(s?u?p?>?)dsq%.?<?/?%2%s*$'   -- détection disqualification
local disqualRepl = '%1<sup><abbr title="disqualification">dsq.</abbr></sup>' -- remplacement disqualification
local tieBreackPattern = '6%s*<sup>%d'                              -- détection tieBreak
local tieBreack5Pattern = '5%s*<sup>%d'                             -- détection tieBreak5
local woPattern = '^[wW]'                                           -- détection WalkOver
local withdrawalPattern = '^[Ff]orfait'                             -- détection forfait
local wotext = '\194\160'                                           -- remplacement de WalkOver
local withdrawaltext = 'forfait'                                    -- remplacement de forfait
local emptyScorePattern = '^[%s\-\.]*$'                             -- détection cellule considérée vide
local emptyText = '\194\160'                                        -- texte cellule vide
local replaceTab = {                                                -- spécifique tête de série de tennis
	q = z.abr {'Q', 'Qualifié(e)', abrd=true},
	wc = '[[Wild card (tennis)|' .. z.abr {'WC', 'Wild card', 'en', abrd=true} ..']]',
	ll = '[[Lucky loser|LL]]',
	alt = '[[Lexique du tennis|' .. z.abr {'Alt', 'Alternate', 'en', abrd=true} .. ']]',
	pr =  '[[Lexique du tennis#PR|' .. z.abr {'PR', 'Protected Ranking', 'en', abrd=true} .. ']]',
	se = '[[Lexique du tennis#SE|' .. z.abr {'SE', 'Special Exempt', 'en', abrd=true} .. ']]',
}

-- table avec les constantes utilisées pour formater les cellules de résultat de match.
local design = { { 
		name = 'background:#F9F9F9; border-width:1px 0 1px 1px;', 
		seed = 'background:#F9F9F9; border-width:1px 1px 1px 0;',
		score = 'background:#EEEEEE; border-width:1px 1px 1px 0;',
		scoreEnd = 'background:#EEEEEE; border-width:1px 1px 1px 0;'
	},
	{
		name = 'background:#F9F9F9; border-width:0 0 1px 1px;', 
		seed = 'background:#F9F9F9; border-width:0 1px 1px 0;',
		score = 'background:#EEEEEE; border-width:0 1px 1px 0;',
		scoreEnd = 'background:#EEEEEE; border-width:0 1px 1px 0;'
	},
	order = {'name', 'seed', 'score' },
	highlight = { 'name', 'seed' },
	highlightColor = 'background:#CCCCFF;'
}

-- setWinner détermine le gangant d'un 'set' et retourne le numéro du gagnant et une raison détectée
-- il est possible de personnalisé la détection en fonction du sport (ex tie-break pour le tennis)
local function setWinner (score, set, sport)
	if score[1][set] == nil and score[2][set] == nil then           -- un score égal à nil générerait une erreur dans la suite du script
		score[1][set] = ''
		score[2][set] = ''
		return 
	end

	local sc1num = tonumber (score[1][set])
	local sc2num = tonumber (score[2][set])
	if sc1num and sc2num then
		if sc1num > sc2num then 
			return 1, 'highestScore' 
		end
		if sc1num < sc2num then 
			return 2, 'highestScore' 
		end
		return  false, 'equals'
	end

	if string.match (score[2][set], retiredPattern) then 
		score[2][set] = string.gsub(score[2][set], retiredPattern, retiredRepl)    -- insertion d'une abréviation sur l'abandon
		return 1, 'retired' 
	end
	if string.match (score[1][set], retiredPattern) then 
		score[1][set] = string.gsub(score[1][set], retiredPattern, retiredRepl)
		score[2][set] = string.gsub(score[2][set], emptyScorePattern, emptyText)
		return 2, 'retired' 
	end
	if string.match (score[2][set], disqualPattern) then 
		score[2][set] = string.gsub(score[2][set], disqualPattern, disqualRepl)    -- insertion d'une abréviation sur la disqualification
		return 1, 'disqualified' 
	end
	if string.match (score[1][set], disqualPattern) then 
		score[1][set] = string.gsub(score[1][set], disqualPattern, disqualRepl)
		score[2][set] = string.gsub(score[2][set], emptyScorePattern, emptyText)
		return 2, 'disqualified' 
	end

	if sport == 'tennis' then
		local winner
		if sc1num == 7 and string.match (score[2][set], tieBreackPattern) then
			winner = 1
		elseif sc2num == 7 and string.match (score[1][set], tieBreackPattern) then
			winner = 2
		end
		if winner then 
			return winner, 'tieBreack' 
		end
		if sc1num == 6 and string.match (score[2][set], tieBreack5Pattern) then
			winner = 1
		elseif sc2num == 6 and string.match (score[1][set], tieBreack5Pattern) then
			winner = 2
		end
		if winner then 
			return winner, 'tieBreack' 
		end
	end

	if string.match(score[1][set], emptyScorePattern) and string.match(score[2][set], emptyScorePattern)  then
		score[1][set] = emptyText
		score[2][set] = emptyText
		return false, 'empty cells'
	end
end

-- détermination du gagnant du match. Met en gras le meilleur score de chaque set.
local function matchWinner (score, sport, nSet)
	if score[1][1] and string.match (score[1][1], woPattern) or score[2][1] and string.match (score[2][1], withdrawalPattern) then
		if score[2][1] and string.match (score[2][1], woPattern) or score[1][1] and string.match (score[1][1], withdrawalPattern) then
			return nil, 'wo'
		else
			return 1, 'wo'
		end
	end
	if score[2][1] and string.match (score[2][1], woPattern) or score[1][1] and string.match (score[1][1], withdrawalPattern) then
		return 2, 'wo'
	end

	local  w, r, winner, reason
	for i = nSet, 1, -1 do
		w, r = setWinner (score, i, sport)
		if w == nil then 
			return 'undefined'
		elseif type(w) == 'number' then
			score[w][i] = '<strong>' .. score[w][i] .. '</strong>'
			if winner == nil then
				winner, reason = w, r
			end
		end
	end
	return winner, reason
end

-- add abbreviation to data in seed field
local function seedAbbr (seedString)
	if (type (seedString) == 'string') and (seedString ~= '') then
		local seed, abr = string.match (seedString, '^%s*%(?%s*(%d?%d?)%s*/?%s*(%a*)%s*%)?%s*$')
		if  type (seed) == 'string' and (string.len (seed) > 0 or string.len (abr) > 0) then
			abr = replaceTab [string.lower (abr)] or abr
			if string.len (seed) > 0 and string.len (abr) > 0 then
				seedString = '(' .. seed .. '/' .. abr .. ')'
			else
				seedString = '(' .. seed .. abr .. ')'    
			end
		end
	end

	return seedString
end

-- prépare le rendu wikiTexte du match (une ligne pour chaque 'joueur')
local function matchDisplay (score, nSet, sport, colsp, highlight)
	local winner, reason = matchWinner (score, sport, nSet)
	local matchCells = { { }, { } }
	local matchLine = { }
	local baseDesign = '\n|rowspan="2" style="border-style:solid;border-color:#999999; padding:0;'
	if colsp == nil  then colsp = '1' end

	for i=1, 2 do
		-- préparation de la cellule du nom
		matchCells[i].name = baseDesign .. 'padding-left:3px; text-align:left;' .. design[i].name .. '" colspan="'  .. colsp  .. '" class="tableau_coupe_name"|'

		-- préparation de la cellule "tête de série"
		matchCells[i].seed = baseDesign .. design[i].seed .. '"|'
		if sport == 'tennis' then
			score[i].seed = seedAbbr (score[i].seed)
		end
		
		if winner == i then 
			matchCells[i].name = matchCells[i].name .. '<strong>' .. score[i].name .. '</strong>'
			matchCells[i].seed = matchCells[i].seed .. '<strong>' .. score[i].seed .. '</strong>'
		else
			matchCells[i].name = matchCells[i].name .. score[i].name
			matchCells[i].seed = matchCells[i].seed .. score[i].seed
		end

		-- préparation des cellules de score
		if not winner then
			if reason == 'wo' then
				matchCells[i].score = baseDesign .. design[i].scoreEnd ..'" colspan="' .. nSet.. '"|' .. withdrawaltext
			else
				matchCells[i].score = baseDesign .. design[i].scoreEnd ..'" colspan="' .. nSet.. '"|' .. emptyText
			end
		elseif winner == i and reason == 'wo' then
			matchCells[i].score = baseDesign .. design[i].scoreEnd ..'" colspan="' .. nSet.. '"|' .. wotext
		elseif winner == 3-i and reason == 'wo' then
			matchCells[i].score = baseDesign .. design[i].scoreEnd ..'" colspan="' .. nSet.. '"|' .. withdrawaltext
		else 
			matchCells[i].score = ''
			for j = 1, nSet - 1 do
				matchCells[i].score = matchCells[i].score .. baseDesign .. design[i].score .. '"|' .. score[i][j]
			end
			matchCells[i].score = matchCells[i].score .. baseDesign .. design[i].scoreEnd .. '"|' .. score[i][nSet]
		end

		-- surlignage du vainqueur
		if highlight and winner == i and sport == 'tennis' then
			for _, v in pairs( design.highlight ) do
				matchCells[i][v] = matchCells[i][v]:gsub( 'background:[#%w]+;', design.highlightColor )
			end
		end

		matchLine[i] = matchCells[i][design.order[1]] .. matchCells[i][design.order[2]] .. matchCells[i][design.order[3]]
	end

	return matchLine    
end
  
-- Préparation du score et exécution de la fonction de mise en forme du match
local function matchPrep (pargs, nSet, start, seed1, seed2, sport, colspan, highlight)
	local score = { 
		{seed = pargs[seed1] or '', name = pargs[start] or ''}, 
		{seed = pargs[seed2] or '', name = pargs[start + nSet + 1] or '' } 
		} 
	for i = 1, nSet do 
		score[1][i] = string.match( pargs[start + i ] or '', '^%s*([^\n]*)%s*$')
		score[2][i] = string.match( pargs[start + i + nSet + 1] or '', '^%s*([^\n]*)%s*$')
	end
	return matchDisplay (score, nSet, sport, colspan, highlight)
end

-- préparation texte pour indication des date et durée du match
local function date_duration (pargs, nSet, name, colspan, dateLine)
	 local wikiText
	 local matchDate = pargs[name .. '-date']
	 local matchDuration = pargs[name .. '-durée']
	 if colspan == nil then 
		colspan = 2 
	end

	local dateBorder, dateColspan = '', ''
	if dateLine then 
		dateBorder = ' border-right: solid 1px #999999;'
		dateColspan = '\n|colspan="2"|'
	end

	if dateLine or matchDate or matchDuration then
		local lineHeight = '0;'
		if matchDate or matchDuration then lineHeight = '11px;'
		end
		wikiText = '\n|colspan="' .. colspan .. '" rowspan="2" style="text-align:left; vertical-align:bottom; line-height:' .. lineHeight
			..  dateBorder .. '"|<small>' .. (matchDate or '') .. '</small>'
			.. dateColspan
			.. '\n|colspan="' .. nSet .. '" rowspan="2" style="vertical-align:bottom; line-height:11px;"|<small>' 
			.. (matchDuration or '') ..  '</small>'
	else
		wikiText = '\n|colspan="' .. (colspan + nSet) .. '" rowspan="2"|'
	end

	 return wikiText
end

-- calcul du nombre de set dans la (les) finale(s) en fonction du nombre de tour du tableau et du nombre de paramètre transmis
local function finalsSets (pargs, nSet, nRound)
	local nArg = 0                  -- nombre de paramètres si tous les matchs dont la finale se jouent en nSet.
	local nSetFinal, nSetFinal2     -- nombre de sets de la finale et de la petite finale
	for i = 1, nRound do
		nArg = nArg + 2 ^ (i) * (nSet + 1)
	end
	if nSet == 3 then
		if pargs[nArg + 5] then                      -- s'il y a un paramètre nArg + 5, il y a une petite finale
			if pargs[nArg + 9] then                  -- la finale est en 5 sets
				if pargs[nArg + 13] then              -- la petite finale aussi
					nSetFinal = 5
					nSetFinal2 = 5
				else
					if pargs['DF 3 sets'] == 'oui' then
						nSetFinal = 3
						nSetFinal2 = 5
					else
						nSetFinal = 5
						nSetFinal2 = 3
					end
				end
			else
				nSetFinal = 3
				nSetFinal2 = 3
			end
		else
			if pargs[nArg + 1] then                  -- s'il y a un paramètre nArg + 1, la finale est en 5 set
				nSetFinal = 5
			else
				nSetFinal = 3
			end
		end
	elseif nSet == 5 then
		nSetFinal = 5
		if pargs[nArg + 9] then
			nSetFinal2 = 5
		elseif    pargs[nArg + 1] then
			nSetFinal2 = 3
		end
	end
	
	return nSetFinal, nSetFinal2
end

-- fonction qui retourne false si l'arugment n'existe pas ou est 'vide'
local function noramalizeBlankArg (argValue)
	local value = string.match (argValue or '', '^%s*(.-)%s*$')
	return value ~= '' and value
end

-- fonction pour tester si des joueurs ont été précisés dans les deux matchs suivants
local function hasPlayer (pargs, nSet, arg)
	local match1 = string.match(pargs[arg] or 'x', '%S') or string.match(pargs[arg + 1 + nSet] or '', '%S')
	local match2 = string.match(pargs[arg + 2 * (1 + nSet)] or 'x', '%S') or string.match(pargs[arg + 3 * (1 + nSet)] or '', '%S')
	return match1, match2
end

-- fonctions pour l'assemblage du premier tour
local function firstRoundMatchs (pargs, nSet, argMatch, seedName, seedNumber, sport)
	local namesMatch1, namesMatch2 = hasPlayer(pargs, nSet, argMatch)
	local line1, line3, line6, line7, line9, match
	local lineEnd = 'border-style:solid;border-color:#999999"|&nbsp;'   -- fin du texte (toujours identique) des cellules générant une ligne de liason
	local noMatch = '\n|colspan="' .. (2 + nSet) .. '" rowspan="2"|'    -- remplace un match lorsqu'il n'y a pas de joueur
	if namesMatch1 then
		match = matchPrep (pargs, nSet, argMatch, seedName .. seedNumber, seedName .. (seedNumber + 1), sport)
		line1 = match[1]             
				.. '\n|rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
				.. '\n|rowspan="5" style="border-width:0 0 1px 0;' .. lineEnd
		line3 = match[2]   
				.. '\n|rowspan="3" style="border-width:0 1px 0 0;' .. lineEnd
	else
		if namesMatch2 then
			line1 = noMatch
					.. '\n|rowspan="2"|&nbsp;' 
					.. '\n|rowspan="5" style="border-width:0 0 1px 0;' .. lineEnd
		else
			line1 = noMatch
					.. '\n|rowspan="2"|&nbsp;' 
					.. '\n|rowspan="5"|&nbsp;'
		end
		line3 = noMatch
				.. '\n|rowspan="3"|&nbsp;'
	end
	if namesMatch2 then
		match = matchPrep (pargs, nSet, argMatch + 2 * (1 + nSet), seedName .. (seedNumber + 2), seedName .. (seedNumber + 3), sport)
		line6 = '\n|rowspan="3" style="border-width:0 1px 1px 0;' .. lineEnd
		line7 = match[1]
		line9 = match[2]
	else
		line6 = '\n|rowspan="3"|&nbsp;'
		line7 = noMatch
		line9 = noMatch
	end            
	return line1, line3, line6, line7, line9
end
       
-- Définition des hauteur de ligne (sensible sur Firefox) pour regrouper les matchs du premier tour par 2
-- Si le le premier "joueur" contient <br /> la hauteur des cellules est plus importante.
local function addCellsHeight (pargs, wikiTable, firstRoundName, compact)
	local heightTable
	if pargs[1] and string.match(string.lower(pargs[1]), '</?br%s?/?>') then
		if compact then 
			heightTable = {36, 4, 1, 39, 1, 1, 39, 1, 4, 36, 4, 4}
		else
			heightTable = {28, 12, 6, 34, 6, 6, 34, 6, 12, 28, 12, 12}
		end
	else
		if pargs[firstRoundName .. '1-date'] then
			heightTable = {12, 8, 6, 14, 6, 6, 14, 6, 8, 12, 8, 8}
		elseif compact then
			heightTable = {16, 4, 1, 19, 1, 1, 19, 1, 4, 16, 4, 4}
		else    
			heightTable = {12, 8, 3, 17, 3, 3, 17, 3, 8, 12, 8, 8}
		end
	end
	local i = 2
	local j = 12
	while wikiTable[i] do
		wikiTable[i] = 'height="' .. heightTable[j] .. '"|' .. wikiTable[i]
		i = i + 1
		j = j + 1
		if j == 13 then j = 1
		end
	end
end



-- -------------------------------------------------
--   code principal de Modèle:Tableau Coupe 2    --
-- -------------------------------------------------
function z.Tableau2 (frame)
		 -- le tableau doit être ouvert en syntaxe wiki, avec une ligne définissant les largeur de cellule avant de lancer le module.
		local pargs = frame:getParent().args    -- paramètre du modèle
		local nSet = tonumber(frame.args.nSet)  -- nombre de Set (testé avec 3 et 5)
		local sport = frame.args.sport          -- permet d'avoir des tests spécifiques pour déterminer le gagnant de chaque match

		local ligneTitre = ''					-- Parti du tableau contenant les ligne de titres qui n'ont pas la même hauteur de ligne.
		local wikiTable = { }                   -- chaque élément de cette table reprèsentera le wikiTexte d'une ligne du tableau
		local wikiText = ''                     -- pour saisie de texte temporaire.
		local match                             -- reçois les la table avec les deux lignes de chaque match

	-- préparation des titres
		local color = pargs['couleur-titre'] or '#CFCFCF'        -- couleur de fond des titre du tableau
		color = string.gsub (color, '^#?(%x%x%x%x%x%x)$', '#%1')
		local DFtitre = noramalizeBlankArg (pargs['DF-titre']) or 'Finale'

	-- assemblage de 'la' ligne de titre
		ligneTitre = '|-'
					.. '\n|height="23"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DFtitre .. '</strong>'

					.. '\n|-'
					.. '\n|height="7"|'

	-- assemblage des lignes du tableau proprement dit
		wikiTable[1] = date_duration (pargs, nSet, 'DF1')
		wikiTable[2] = ''
  
	-- DF 1
		local highlight = false
		if DFtitre == 'Finale' then
			highlight = true
		end
		match = matchPrep (pargs, nSet, 1, 'DF1', 'DF2', sport, 1, highlight)
		wikiTable[3] = 'height="7"|' .. match[1]
		wikiTable[4] = ''
		wikiTable[5] = 'height="7"|' .. match[2]
  
		wikiText = '\n|- \n|'
	return ligneTitre .. table.concat (wikiTable, wikiText)
end



-- -------------------------------------------------
--   code principal de Modèle:Tableau Coupe 4    --
-- -------------------------------------------------
function z.Tableau4 (frame)
		 -- le tableau doit être ouvert en syntaxe wiki, avec une ligne définissant les largeur de cellule avant de lancer le module.
		local pargs = frame:getParent().args    -- paramètre du modèle
		local nSet = tonumber(frame.args.nSet)  -- nombre de Set (testé avec 3 et 5)
		local sport = frame.args.sport          -- permet d'avoir des tests spécifiques pour déterminer le gagnant de chaque match

		local ligneTitre = ''                   -- Parti du tableau contenant les ligne de titres qui n'ont pas la même hauteur de ligne.
		local wikiTable = { }                   -- chaque élément de cette table reprèsentera le wikiTexte d'une ligne du tableau
		local wikiText = ''                     -- pour saisie de texte temporaire.
		local match                             -- reçois les la table avec les deux lignes de chaque match
		local nSetFinal, nSetFinal2 = finalsSets (pargs, nSet, 2)   
		                                        -- nombre de set de la finale et de la petite finale 

	-- fontion pour connaitre le premier argument non nommé du match n°xx (dans l'ordre de saisie du modèle)
		local function argMatch (xx)
			if xx == 4 then 
				return 1 + (3 - 1) *  2 * (nSet + 1) +  2 * (nSetFinal + 1)
			else
				return 1 + (xx - 1) *  2 * (nSet + 1)
			end
		end


	-- préparation des titres
		local color = pargs['couleur-titre'] or '#CFCFCF'        -- couleur de fond des titre du tableau
		color = string.gsub (color, '^#?(%x%x%x%x%x%x)$', '#%1')
		local DDtitre = noramalizeBlankArg (pargs['DD-titre']) or '1/2 finale'
		local DFtitre = noramalizeBlankArg (pargs['DF-titre']) or 'Finale'

		local extraCells = ''
		if nSetFinal > nSet or (nSetFinal2 or 0) > nSet then
			extraCells = '|width="20"| ||width="20"| \n'      -- Deux cellules supplémentaire lorsque l'une des finale est en 5 sets
		end

	-- assemblage de 'la' ligne de titre
		ligneTitre = extraCells
					.. '|-'
					.. '\n|height="23"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DDtitre .. '</strong>'
					.. '\n|colspan="2"|'
					.. '\n|colspan="' .. (2 + nSetFinal) .. '" style="background:' .. color .. ';"|<strong>' .. DFtitre .. '</strong>'

					.. '\n|-'
					.. '\n|height="7"|'

	-- assemblage des lignes du tableau proprement dit
		for  i = 0, 1 do
			wikiTable[1 + i * 6] = date_duration (pargs, nSet, 'DD' .. (1 + i * 2))
		end
		wikiTable[2] = ''

	-- DD 1-4
		wikiTable[3], wikiTable[5], wikiTable[8], wikiTable[9], wikiTable[11] = firstRoundMatchs (pargs, nSet, argMatch(1), 'DD', 1, sport)
		wikiTable[4] = date_duration (pargs, nSet, 'DF1')

	-- DF 1
		local highlight = false
		if DFtitre == 'Finale' then
			highlight = true
		end
		match = matchPrep (pargs, nSetFinal, argMatch(3), 'DF1', 'DF2', sport, 1, highlight)
		wikiTable[6] = match[1]
		wikiTable[8] =  wikiTable[8] .. '\n|'
					.. match[2]

		wikiTable[10] = ''
		wikiTable[12] = '' 

		if nSetFinal2 then
			wikiTable[12] = '\n|colspan="2"|'
						.. '\n|rowspan="2" colspan="' .. (2 + nSetFinal2) .. '" style="vertical-align:bottom;"|'
						.. '<div style="position:relative;">'
						.. '<div style="position:absolute; bottom:0; left:0; width:100%; padding:2px 0; background:' .. color ..';">'
						.. '<strong>' .. (noramalizeBlankArg (pargs['DP-titre']) or 'Match pour la troisième place') .. '</strong>'
						.. '</div></div>'
			wikiTable[13] = ''
			wikiTable[14] = '\n|rowspan="6" colspan="' .. (4 + nSet) .. '"|'
						.. date_duration (pargs, nSetFinal2, 'DP1')
			wikiTable [15] = ''
	-- DP 1
			match = matchPrep (pargs, nSetFinal2, argMatch(4), 'DP1', 'DP2', sport)
			wikiTable[16] = match[1]
			wikiTable[17] = ''
			wikiTable[18] = match[2]
		end

		-- Définition des hauteur de ligne (sensible sur Firefox) pour regrouper les matchs du premier tour par 2
		-- Si le le premier "joueur" contient <br /> la hauteur des cellules est plus importante.
		local heightTable
		if pargs[1] and string.match(string.lower(pargs[1]), '</?br%s?/?>') then
			heightTable = {32, 8, 8}
		else
				heightTable = {12, 8, 8}
		end
		local i = 2
		local j = 3
		while wikiTable[i]  and i < 15 do
			wikiTable[i] = 'height="' .. heightTable[j] .. '"|' .. wikiTable[i]
			i = i + 1
			j = j + 1
			if j == 4 then j = 1
			end
		end

		wikiText = '\n|- \n|'
	return ligneTitre .. table.concat (wikiTable, wikiText)
end



-- -------------------------------------------------
--   code principal de Modèle:Tableau Coupe 8    --
-- -------------------------------------------------
function z.Tableau8 (frame)
		 -- le tableau doit être ouvert en syntaxe wiki, avec une ligne définissant les largeur de cellule avant de lancer le module.
		local pargs = frame:getParent().args    -- paramètre du modèle
		local nSet = tonumber(frame.args.nSet)  -- nombre de Set (testé avec 3 et 5)
		local sport = frame.args.sport          -- permet d'avoir des tests spécifiques pour déterminer le gagnant de chaque match

		local ligneTitre = ''					-- Parti du tableau contenant les ligne de titres qui n'ont pas la même hauteur de ligne.
		local wikiTable = { }                   -- chaque élément de cette table reprèsentera le wikiTexte d'une ligne du tableau
		local wikiText = ''                     -- pour saisie de texte temporaire.
		local match                             -- reçois les la table avec les deux lignes de chaque match
		local lineEnd = 'border-style:solid;border-color:#999999"|&nbsp;'
		                                        -- fin du texte (toujours identique) des cellules générant une ligne de liason
		local nSetFinal, nSetFinal2 = finalsSets (pargs, nSet, 3)   
		                                        -- nombre de set de la finale et de la petite finale 

	-- fontion pour connaitre le premier argument non nommé du match n°xx (dans l'ordre de saisie du modèle)
		local function argMatch (xx)
			if xx == 8 then 
				return 1 + (7 - 1) *  2 * (nSet + 1) +  2 * (nSetFinal + 1)
			else
				return 1 + (xx - 1) *  2 * (nSet + 1)
			end
		end


	-- préparation des titres
		local color = pargs['couleur-titre'] or '#CFCFCF'        -- couleur de fond des titre du tableau
		color = string.gsub (color, '^#?(%x%x%x%x%x%x)$', '#%1')
		local DQtitre = noramalizeBlankArg (pargs['DQ-titre']) or '1/4 de finale'
		local DDtitre = noramalizeBlankArg (pargs['DD-titre']) or '1/2 finale'
		local DFtitre = noramalizeBlankArg (pargs['DF-titre']) or 'Finale'

		local extraCells = ''
		if nSetFinal > nSet or (nSetFinal2 or 0) > nSet then
			extraCells = '|width="20"| ||width="20"| \n'      -- Deux cellules supplémentaire lorsque l'une des finale est en 5 sets
		end

	-- assemblage de 'la' ligne de titre
		ligneTitre = extraCells
					.. '|-'
					.. '\n|height="23"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DQtitre .. '</strong>'
					.. '\n|colspan="2"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DDtitre .. '</strong>'
					.. '\n|colspan="2"|'
					.. '\n|colspan="' .. (2 + nSetFinal) .. '" style="background:' .. color .. ';"|<strong>' .. DFtitre .. '</strong>'

					.. '\n|-'
					.. '\n|height="7"|'

	-- assemblage des lignes du tableau proprement dit
		for  i = 0, 3 do
			wikiTable[1 + i * 6] = date_duration (pargs, nSet, 'DQ' .. (1 + i * 2))
		end
		wikiTable[2] = ''

	-- DQ 1-4
		wikiTable[3], wikiTable[5], wikiTable[8], wikiTable[9], wikiTable[11] = firstRoundMatchs (pargs, nSet, argMatch(1), 'DQ', 1, sport)
		wikiTable[4] = date_duration (pargs, nSet, 'DD1')

	-- DD 1
		match = matchPrep (pargs, nSet, argMatch(5), 'DD1', 'DD2', sport)
		wikiTable[6] = match[1]
					.. '\n|rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
					.. '\n|rowspan="8" style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[8] =  wikiTable[8] .. '\n|'
					.. match[2]
					.. '\n|rowspan="12" style="border-width:0 1px 1px 0;' .. lineEnd

		wikiTable[10] = '\n|colspan="' .. (3 + nSet) .. '" rowspan="2"|'
					.. date_duration (pargs, nSetFinal, 'DF1')

	-- DF 1
		local highlight = false
		if DFtitre == 'Finale' then
			highlight = true
		end
		match = matchPrep (pargs, nSetFinal, argMatch(7), 'DF1', 'DF2', sport, 1, highlight)
		wikiTable[12] = '\n|colspan="' .. (4 + nSet) ..'" rowspan="3"|'
					.. match[1]
		wikiTable[14] = '\n|'
					.. match[2]

	-- DQ 5-8
		wikiTable[15], wikiTable[17], wikiTable[20], wikiTable[21], wikiTable[23] = firstRoundMatchs (pargs, nSet, argMatch(3), 'DQ', 5, sport)
		wikiTable[16] = date_duration (pargs, nSet, 'DD3')

	-- DD 3
		match = matchPrep (pargs, nSet, argMatch(6), 'DD3', 'DD4', sport)
		wikiTable[18] = match[1]
		wikiTable[20] =  wikiTable[20] .. '\n|'
					.. match[2]
		
		wikiTable[22] = ''
		wikiTable[24] = ''

		if nSetFinal2 then
			wikiTable[20] =  wikiTable[20] .. '\n|colspan="2"|'
						.. '\n|rowspan="2" colspan="' .. (2 + nSetFinal2) .. '" style="vertical-align:bottom;"|'
						.. '<div style="position:relative;">'
						.. '<div style="position:absolute; bottom:0; left:0; width:100%; padding:2px 0; background:' .. color ..';">'
						.. '<strong>' .. (noramalizeBlankArg (pargs['DP-titre']) or 'Match pour la troisième place') .. '</strong>'
						.. '</div></div>'
			wikiTable[22] = '\n|colspan="' .. (5 + nSet) .. '"|'
						.. date_duration (pargs, nSetFinal2, 'DP1')
	-- DP 1            
			match = matchPrep (pargs, nSetFinal2, argMatch(8), 'DP1', 'DP2', sport)
			wikiTable[24] = '\n|rowspan="4" colspan="' .. (6 + nSet) .. '"|'
						.. match[1]
			wikiTable[25] = '\n|rowspan="2" colspan="' .. (2 + nSet) .. '"|'
			wikiTable[26] = match[2]
		end

		-- Définition des hauteur de ligne (sensible sur Firefox) pour regrouper les matchs du premier tour par 2
		-- Si le le premier "joueur" contient <br /> la hauteur des cellules est plus importante.
		addCellsHeight (pargs, wikiTable, 'DQ')

		wikiText = '\n|- \n|'
	return ligneTitre .. table.concat (wikiTable, wikiText)
end



-- -------------------------------------------------
--   code principal de Modèle:Tableau Coupe 16    --
-- -------------------------------------------------
function z.Tableau16 (frame)
		 -- le tableau doit être ouvert en syntaxe wiki, avec une ligne définissant les largeur de cellule avant de lancer le module.
		local pargs = frame:getParent().args    -- paramètre du modèle
		local nSet = tonumber(frame.args.nSet)  -- nombre de Set (testé avec 3 et 5)
		local sport = frame.args.sport          -- permet d'avoir des tests spécifiques pour déterminer le gagnant de chaque match
		local compact = frame.args.compact 
			or pargs.compact                    -- permet un tableau avec moins d'espaces lorsqu'il n'y a pas de dates.
		local ligneTitre = ''					-- Parti du tableau contenant les ligne de titres qui n'ont pas la même hauteur de ligne.
		local wikiTable = { }                   -- chaque élément de cette table reprèsentera le wikiTexte d'une ligne du tableau
		local wikiText = ''                     -- pour saisie de texte temporaire.
		local match                             -- reçois les la table avec les deux lignes de chaque match
		local lineEnd = 'border-style:solid;border-color:#999999"|&nbsp;'      
		                                        -- fin du texte (toujours identique) des cellules générant une ligne de liason
		local nSetFinal, nSetFinal2 = finalsSets (pargs, nSet, 4)   
		                                        -- nombre de set de la finale et de la petite finale 


	-- fontion pour connaitre le premier argument non nommé du match n°xx (dans l'ordre de saisie du modèle)
		local function argMatch (xx)
			if xx == 16 then 
				return 1 + (15 - 1) *  2 * (nSet + 1) +  2 * (nSetFinal + 1)
			else
				return 1 + (xx - 1) *  2 * (nSet + 1)
			end
		end

	-- préparation des titres
		local color = pargs['couleur-titre'] or '#CFCFCF'        -- couleur de fond des titre du tableau
		color = string.gsub (color, '^#?(%x%x%x%x%x%x)$', '#%1')
		local premiersTours = pargs['premiers tours']
		local DHtitre = noramalizeBlankArg (pargs['DH-titre'])
		local DQtitre = noramalizeBlankArg (pargs['DQ-titre'])
		local DDtitre = noramalizeBlankArg (pargs['DD-titre'])
		local DFtitre = noramalizeBlankArg (pargs['DF-titre'])
		local DFt = string.lower(DFtitre or '')
		if pargs['premiers tours'] then 
			DHtitre = z.abr {'1<sup>er</sup>', 'Premier', abrd = true} .. ' tour'
			DQtitre = z.abr {'2<sup>e</sup>', 'Deuxième', abrd = true} .. ' tour'
			DDtitre = z.abr {'3<sup>e</sup>', 'Troisième', abrd = true} .. ' tour'
			DFtitre = '1/8 de finale'
		elseif DFt == '1/8 de finale' or DFt == 'hf' then
			DHtitre = DHtitre or z.abr {'1<sup>er</sup>', 'Premier', abrd = true} .. ' tour'
			DQtitre = DQtitre or z.abr {'2<sup>e</sup>', 'Deuxième', abrd = true} .. ' tour'
			DDtitre = DDtitre or z.abr {'3<sup>e</sup>', 'Troisième', abrd = true} .. ' tour'
			DFtitre = '1/8 de finale'
		elseif DFt == '1/4 de finale' or DFt == 'qf' then
			DHtitre = DHtitre or z.abr {'1<sup>er</sup>', 'Premier', abrd = true} .. ' tour'
			DQtitre = DQtitre or z.abr {'2<sup>e</sup>', 'Deuxième', abrd = true} .. ' tour'
			DDtitre = DDtitre or '1/8 de finale'
			DFtitre = '1/4 de finale'
		elseif DFt == '1/2 finale' or DFt == 'df' then
			DHtitre = DHtitre or z.abr {'1<sup>er</sup>', 'Premier', abrd = true} .. ' tour'
			DQtitre = DQtitre or '1/8 de finale'
			DDtitre = DDtitre or '1/4 de finale'
			DFtitre = '1/2 finale'                
		else
			DHtitre = DHtitre or '1/8 de finale'
			DQtitre = DQtitre or '1/4 de finale'
			DDtitre = DDtitre or '1/2 finale'
			DFtitre = DFtitre or 'Finale'
		end

		local extraCells = ''
		if nSetFinal > nSet or (nSetFinal2 or 0) > nSet then
			extraCells = '|width="20"| ||width="20"| \n'      -- Deux cellules supplémentaire lorsque l'une des finale est en 5 sets
		end

	-- assemblage de 'la' ligne de titre
		ligneTitre = extraCells
					.. '|-'
					.. '\n|height="23"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DHtitre .. '</strong>'
					.. '\n|colspan="2"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DQtitre .. '</strong>'
					.. '\n|colspan="2"|'
					.. '\n|colspan="' .. (4 + nSet + nSetFinal) 
					.. '" style="background:' .. color .. ';"|<strong>' .. DFtitre .. '</strong>'
		
					.. '\n|-'
					.. '\n|height="2" colspan="25"|'
		
					.. '\n|-'
					.. '\n|'
					.. '\n|colspan="' .. (5 + nSet) .. '"|'
					.. '\n|colspan="' .. (4 + 2 * nSet) .. '"|'
					.. '<div style="position:relative;">'
					.. '<div style="position:absolute; left:0; width:100%; padding:2px 0; background:' .. color ..';">'
					.. '<strong>' .. DDtitre .. '</strong>'
					.. '</div></div>'
					
					.. '\n|-'
					.. '\n|height="5"|'

	-- assemblage des lignes du tableau proprement dit
		for  i = 0, 7 do
			wikiTable[i * 6 + 1] = date_duration (pargs, nSet, 'DH' .. (i * 2 + 1))
		end
		wikiTable[2] = ''

	-- DH 1-16
		for i = 0, 3 do
			wikiTable[i * 12 + 3], 
			wikiTable[i * 12 + 5], 
			wikiTable[i * 12 + 8], 
			wikiTable[i * 12 + 9], 
			wikiTable[i * 12 + 11]   
				= firstRoundMatchs (pargs, nSet, argMatch(i * 2 + 1), 'DH', i * 4 + 1, sport)
		end
		
		wikiTable[4] = date_duration (pargs, nSet, 'DQ1')

	-- DQ 1
		match = matchPrep (pargs, nSet, argMatch(9), 'DQ1', 'DQ2', sport)
		wikiTable[6] = match[1]   
					.. '\n|rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[8] = wikiTable[8] .. '\n|'
					.. match[2]  
					.. '\n|rowspan="2" style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[10] = '\n|colspan="2"|'
					.. date_duration (pargs, nSet, 'DD1', 2 + nSet, true)

	-- DD 1
		match = matchPrep (pargs, nSet, argMatch(13), 'DD1', 'DD2', sport, 3 + nSet)
		wikiTable[12] = '\n|colspan="3" rowspan="3"|'
					.. match[1]   
					.. '\n|rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[14] = match[2]  
					.. '\n|rowspan="8" style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[16] = date_duration (pargs, nSet, 'DQ3')
					.. '\n|rowspan="4" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DQ 3
		match = matchPrep (pargs, nSet, argMatch(10), 'DQ3', 'DQ4', sport)
		wikiTable[18] = match[1]   
		wikiTable[20] = wikiTable[20] .. '\n|'
					.. match[2]  

		wikiTable[22] = '\n|colspan="' .. (5 + nSet) .. '"|'
					.. date_duration (pargs, nSetFinal, 'DF1', 2 + nSet, true)
		
	-- DF 1
		local highlight = false
		if DFtitre == 'Finale' then
			highlight = true
		end
		match = matchPrep (pargs, nSetFinal, argMatch(15), 'DF1', 'DF2', sport, 3 + nSet, highlight)
		wikiTable[24] = '\n|colspan="' .. (6 + nSet) .. '" rowspan="3"|'
					.. match [1]
		wikiTable[26] = match [2]

		wikiTable[28] = date_duration (pargs, nSet, 'DQ5')
					.. '\n|colspan="' .. (3 + nSet) .. '" rowspan="2"|'
					.. '\n|rowspan="10" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DQ 5
		match = matchPrep (pargs, nSet, argMatch(11), 'DQ5', 'DQ6', sport)
		wikiTable[30] = match[1]
						.. '\n|rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[32] = wikiTable[32] .. '\n|rowspan="2"|'
					.. match[2] 
					.. '\n|rowspan="2" style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[34] = '\n|colspan="2"|'
					.. date_duration (pargs, nSet, 'DD3', 2 + nSet, true)

	-- DD3
		match = matchPrep (pargs, nSet, argMatch(14), 'DD3', 'DD4', sport, 3 + nSet)
		wikiTable[36] = '\n|colspan="3" rowspan="3"|'
					.. match[1]
		wikiTable[38] = match[2]

		wikiTable[40] = date_duration (pargs, nSet, 'DQ7')
					.. '\n|rowspan="4" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DQ 7
		match = matchPrep (pargs, nSet, argMatch(12), 'DQ7', 'DQ8', sport)
		wikiTable[42] = match[1]
		wikiTable[44] = wikiTable[44] .. '\n|rowspan="2"|'
					.. match[2]

		wikiTable[46] = ''
		wikiTable[48] = ''

		if nSetFinal2 then
			wikiTable[44] = wikiTable[44] .. '\n|colspan="2"|'
						.. '\n|rowspan="2" colspan="' .. (4 + nSet + nSetFinal2) .. '" style="vertical-align:bottom;"|'
						.. '<div style="position:relative;">'
						.. '<div style="position:absolute; bottom:0; left:0; width:100%; padding:2px 0; background:' .. color ..';">'
						.. '<strong>' .. (noramalizeBlankArg (pargs['DP-titre']) or 'Match pour la troisième place') .. '</strong>'
						.. '</div></div>'
			wikiTable[46] = '\n|colspan="' .. (5 + nSet) .. '"|'
						.. date_duration (pargs, nSetFinal2, 'DP1', 4 + nSet)
	-- DP1
			match = matchPrep (pargs, nSetFinal2, argMatch(16), 'DP1', 'DP2', sport, 3 + nSet)
			wikiTable[48] = '\n|rowspan="4" colspan="' .. (6 + nSet) .. '"|'
						.. match[1]
			wikiTable[49] = '\n|rowspan="2" colspan="' .. (2 + nSet) .. '"|'
			wikiTable[50] = match[2]
		end

		-- Définition des hauteur de ligne (sensible sur Firefox) pour regrouper les matchs du premier tour par 2
		-- Si le le premier "joueur" contient <br /> la hauteur des cellules est plus importante.
		addCellsHeight (pargs, wikiTable, 'DH', compact)

		wikiText = '\n|- \n|'
	return ligneTitre .. table.concat (wikiTable, wikiText)
end



-- -------------------------------------------------
--   code principal de Modèle:Tableau Coupe 32    --
-- -------------------------------------------------
function z.Tableau32 (frame)
		 -- le tableau doit être ouvert en syntaxe wiki, avec une ligne définissant les largeur de cellule avant de lancer le module.
		local pargs = frame:getParent().args    -- paramètre du modèle
		local nSet = tonumber(frame.args.nSet)  -- nombre de Set (testé avec 3 sets)
		local sport = frame.args.sport          -- permet d'avoir des tests spécifiques pour déterminer le gagnant de chaque match

		local ligneTitre = ''					-- Parti du tableau contenant les ligne de titres qui n'ont pas la même hauteur de ligne.
		local wikiTable = { }                   -- chaque élément de cette table reprèsentera le wikiTexte d'une ligne du tableau
		local wikiText = ''                     -- pour saisie de texte temporaire.
		local match                             -- reçois les la table avec les deux lignes de chaque match
		local lineEnd = 'border-style:solid;border-color:#999999"|&nbsp;'      
		                                        -- fin du texte (toujours identique) des cellules générant une ligne de liason
		local nSetFinal, nSetFinal2 = finalsSets (pargs, nSet, 5)   
		                                        -- nombre de set de la finale et de la petite finale 
		
		-- fontion pour connaitre le premier argument non nommé du match n°xx (dans l'ordre de saisie du modèle)
		local function argMatch (xx)
			if xx == 32 then 
				return 1 + (31 - 1) *  2 * (nSet + 1) +  2 * (nSetFinal + 1)
			else
				return 1 + (xx - 1) *  2 * (nSet + 1)
			end
		end

	-- préparation des titres
		local color = pargs['couleur-titre'] or '#CFCFCF'        -- couleur de fond des titre du tableau
		color = string.gsub (color, '^#?(%x%x%x%x%x%x)$', '#%1')
		local premiersTours = pargs['premiers tours']
		local DStitre = noramalizeBlankArg (pargs['DS-titre']) or z.abr {'1<sup>er</sup>', 'Premier', abrd = true} .. ' tour'
		local DHtitre = noramalizeBlankArg (pargs['DH-titre']) or z.abr {'2<sup>e</sup>', 'Deuxième', abrd = true} .. ' tour'
		local DQtitre = noramalizeBlankArg (pargs['DQ-titre'])
		local DDtitre = noramalizeBlankArg (pargs['DD-titre'])
		local DFtitre = noramalizeBlankArg (pargs['DF-titre'])
		local DFt = string.lower(DFtitre or '')
		if pargs['premiers tours'] then 
			DQtitre = z.abr {'3<sup>e</sup>', 'Troisième', abrd = true} .. ' tour'
			DDtitre = '1/8 de finale'
			DFtitre = '1/4 de finale'
		elseif DFt == '1/8 de finale' or DFt == 'hf' then
			DQtitre = DQtitre or z.abr {'3<sup>e</sup>', 'Troisième', abrd = true} .. ' tour'
			DDtitre = DDtitre or z.abr {'4<sup>e</sup>', 'Quatrième', abrd = true} .. ' tour'
			DFtitre = '1/8 de finale'
		elseif DFt == '1/4 de finale' or DFt == 'qf' then
			DQtitre = DQtitre or z.abr {'3<sup>e</sup>', 'Troisième', abrd = true} .. ' tour'
			DDtitre = DDtitre or '1/8 de finale'
			DFtitre = '1/4 de finale'
		elseif DFt == '1/2 finale' or DFt == 'df' then
			DQtitre = DQtitre or '1/8 de finale'
			DDtitre = DDtitre or '1/4 de finale'
			DFtitre = '1/2 finale'
		else
			DQtitre = DQtitre or '1/4 de finale'
			DDtitre = DDtitre or '1/2 finale'
			DFtitre = DFtitre or 'Finale'
		end
		
		local extraCells = ''
		if nSetFinal > nSet or (nSetFinal2 or 0) > nSet then
			extraCells = '|width="20"| ||width="20"| \n'      -- Deux cellules supplémentaire lorsque l'une des finale est en 5 sets
		end

	-- assemblage de 'la' ligne de titre
		ligneTitre = extraCells
					.. '|-'
					.. '\n|height="23"|'
					.. '\n|colspan="' .. (2 + nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DStitre .. '</strong>'
					.. '\n|colspan="3"|'
					.. '\n|colspan="' .. (6 + 2 * nSet) .. '" style="background:' .. color .. ';"|<strong>' .. DQtitre .. '</strong>'
					.. '\n|'
					.. '\n|colspan="' .. (6 + 2 * nSetFinal) .. '" style="background:' .. color .. ';"|<strong>' .. DFtitre .. '</strong>'
		
					.. '\n|-'
					.. '\n|height="2" colspan="34"|'
		
					.. '\n|-'
					.. '\n|'
					.. '\n|colspan="' .. (4 + nSet) .. '"|'
					.. '\n|colspan="' .. (3 + nSet) .. '"|'
					.. '<div style="position:relative;">'
					.. '<div style="position:absolute; left:0; width:100%; padding:2px 0; max-height:19px; background:' .. color ..';">'
					.. '<strong>' .. DHtitre .. '</strong>'
					.. '</div></div>'
					.. '\n|'
					.. '\n|colspan="' .. (7 + 2 * nSet) .. '"|'
					.. '<div style="position:relative;">'
					.. '<div style="position:absolute; left:0; width:100%; padding:2px 0; max-height:19px; background:' .. color ..';">'
					.. '<strong>' .. DDtitre .. '</strong>'
					.. '</div></div>'
		
					.. '\n|-'
					.. '\n|height="5"|'

	-- assemblage des lignes du tableau proprement dit
	
		for  i = 0, 15 do
			wikiTable[6 * i + 1] = date_duration (pargs, nSet, 'DS' .. (2 * i + 1))
		end
		wikiTable[2] = ''
		
	-- DS 1-32
		for i = 0, 7 do
			wikiTable[i * 12 + 3], 
			wikiTable[i * 12 + 5], 
			wikiTable[i * 12 + 8], 
			wikiTable[i * 12 + 9], 
			wikiTable[i * 12 + 11]   
				= firstRoundMatchs (pargs, nSet, argMatch(i * 2 + 1), 'DS', i * 4 + 1, sport)
		end
		wikiTable[4] = date_duration (pargs, nSet, 'DH1', 3)

	-- DH 1
		match = matchPrep (pargs, nSet, argMatch(17), 'DH1', 'DH2', sport, 2)
		wikiTable[6] = match[1]
					.. '\n|colspan=2 rowspan=2 style="border-width:0 0 1px 0;' .. lineEnd

		wikiTable[8] =  wikiTable[8] .. '\n|'
					.. match[2]
					.. '\n|colspan=2 rowspan=4 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[10] = '\n|colspan="2"|' 
					.. date_duration (pargs, nSet, 'DQ1', 4 + nSet, true)

	-- DQ 1
		match = matchPrep (pargs, nSet, argMatch(25), 'DQ1', 'DQ2', sport, 5 + nSet)
		wikiTable[12] = '\n|colspan=3 rowspan=3|'
					.. match[1]
					.. '\n|colspan=2 rowspan=2 style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[13] = date_duration (pargs, nSet, 'DS5')
		wikiTable[14] = match[2]
					.. '\n|colspan=2 rowspan=10 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[16] = date_duration (pargs, nSet, 'DH3', 3)
					.. '\n|colspan=2 rowspan=4 style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 3
		match = matchPrep (pargs, nSet, argMatch(18), 'DH3', 'DH4', sport, 2)
		wikiTable[18] = match[1]
		 wikiTable[20] = wikiTable[20] ..'\n|'
					.. match[2]

		wikiTable[22] = '\n|colspan="' .. (5 + nSet) .. '"|'
					.. date_duration (pargs, nSet, 'DD1', 5 + nSet, true)

	-- DD 1
		match = matchPrep (pargs, nSet, argMatch(29), 'DD1', 'DD2', sport, 6 + nSet)
		wikiTable[24] = '\n|colspan="' .. (6 + nSet) .. '" rowspan="3"|'
					.. match[1]
					.. '\n|rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[26] = match[2]
					.. '\n|rowspan=22 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[28] = date_duration (pargs, nSet, 'DH5', 3)
					.. '\n|colspan="' .. (4 + nSet) .. '"|'
					.. '\n|colspan="2" rowspan="10" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 5
		match = matchPrep (pargs, nSet, argMatch(19), 'DH5', 'DH6', sport, 2)
		wikiTable[30] = match[1]
					.. '\n|colspan=2 rowspan=2 style="border-width:0 0 1px 0;' .. lineEnd
		 wikiTable[32] = wikiTable[32] .. '\n|'
					.. match[2]
					.. '\n|colspan=2 rowspan=4 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[34] = '\n|colspan="2"|' 
					.. date_duration (pargs, nSet, 'DQ3', 4 + nSet, true)

	-- DQ 3
		match = matchPrep (pargs, nSet, argMatch(26), 'DQ3', 'DQ4', sport, 5 + nSet)
		wikiTable[36] = '\n|colspan=3 rowspan=3|'
					.. match[1]
		wikiTable[38] = match[2]

		wikiTable[40] = date_duration (pargs, nSet, 'DH7', 3)
					.. '\n|colspan="2" rowspan="4" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 7
		match = matchPrep (pargs, nSet, argMatch(20), 'DH7', 'DH8', sport, 2)
		wikiTable[42] = match[1]
		 wikiTable[44] = wikiTable[44] ..'\n|'
					.. match[2]

		wikiTable[46] = '\n|colspan="' .. (9 + 2 * nSet) .. '"|'
					.. date_duration (pargs, nSetFinal, 'DF1', 4 + nSet, true)

	-- DF 1
		local highlight = false
		if DFtitre == 'Finale' then
			highlight = true
		end
		match = matchPrep (pargs, nSetFinal, argMatch(31), 'DF1', 'DF2', sport, 5 + nSet, highlight)
		wikiTable[48] = '\n|colspan="' .. (10 + 2 * nSet) .. '" rowspan="3"|'
					.. match[1]
		wikiTable[50] = match[2]

		wikiTable[52] = date_duration (pargs, nSet, 'DH9', 3)
					.. '\n|colspan="' .. (8 + 2 * nSet) .. '"|'
					.. '\n|rowspan="22" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 9
		match = matchPrep (pargs, nSet, argMatch(21), 'DH9', 'DH10', sport, 2)
		wikiTable[54] = match[1]
					.. '\n|colspan=2 rowspan=2 style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[56] = wikiTable[56] ..'\n|'
					.. match[2]
					.. '\n|colspan=2 rowspan=4 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[58] = '\n|colspan="2"|' 
					.. date_duration (pargs, nSet, 'DQ5', 4 + nSet, true)

	-- DQ 5
		match = matchPrep (pargs, nSet, argMatch(27), 'DQ5', 'DQ6', sport, 5 + nSet)
		wikiTable[60] = '\n|colspan="3" rowspan="3"|'
					.. match[1]
					.. '\n|colspan="2" rowspan="2" style="border-width:0 0 1px 0;' .. lineEnd
		wikiTable[62] = match[2]
					.. '\n|colspan=2 rowspan=10 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[64] = date_duration (pargs, nSet, 'DH11', 3)
					.. '\n|colspan="2" rowspan="4" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 11
		match = matchPrep (pargs, nSet, argMatch(22), 'DH11', 'DH12', sport, 2)
		wikiTable[66] = match[1]
		 wikiTable[68] = wikiTable[68] ..'\n|'
					.. match[2]

		wikiTable[70] = '\n|colspan="' .. (5 + nSet) .. '"|'
					.. date_duration (pargs, nSet, 'DD3', 5 + nSet, true)

	-- DD 3
		match = matchPrep (pargs, nSet, argMatch(30), 'DD3', 'DD4', sport, 6 + nSet)
		wikiTable[72] = '\n|colspan="' .. (6 + nSet) .. '" rowspan="3"|'
					.. match[1]
		wikiTable[74] = match[2]

		wikiTable[76] = date_duration (pargs, nSet, 'DH13', 3)
					.. '\n|colspan="' .. (4 + nSet) .. '"|'
					.. '\n|colspan="2" rowspan="10" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 13
		match = matchPrep (pargs, nSet, argMatch(23), 'DH13', 'DH14', sport, 2)
		wikiTable[78] = match[1]
					.. '\n|colspan=2 rowspan=2 style="border-width:0 0 1px 0;' .. lineEnd
		 wikiTable[80] = wikiTable[80] ..'\n|'
					.. match[2]
					.. '\n|colspan=2 rowspan=4 style="border-width:0 1px 0 0;' .. lineEnd

		wikiTable[82] = '\n|colspan="2"|' 
					.. date_duration (pargs, nSet, 'DQ7', 4 + nSet, true)

	-- DQ 7
		match = matchPrep (pargs, nSet, argMatch(28), 'DQ7', 'DQ8', sport, 5 + nSet)
		wikiTable[84] = '\n|colspan=3 rowspan=3|'
					.. match[1]
		wikiTable[86] = match[2]

		wikiTable[88] = date_duration (pargs, nSet, 'DH15', 3)
					.. '\n|colspan="2" rowspan="4" style="border-width:0 1px 1px 0;' .. lineEnd

	-- DH 15
		match = matchPrep (pargs, nSet, argMatch(24), 'DH15', 'DH16', sport, 2)
		wikiTable[90] = match[1]
		 wikiTable[92] = wikiTable[92] ..'\n|'
					.. match[2]

		wikiTable[94] = ''
		wikiTable[96] = ''
		
		if nSetFinal2 then
			wikiTable[92] = wikiTable[92] .. '\n|colspan="' .. (5 + nSet) .. '"|'
						.. '\n|rowspan="2" colspan="' .. (6 + nSet + nSetFinal2) .. '" style="vertical-align:bottom;"|'
						.. '<div style="position:relative;">'
						.. '<div style="position:absolute; bottom:0; left:0; width:100%; padding:2px 0; background:' .. color ..';">'
						.. '<strong>' .. (noramalizeBlankArg (pargs['DP-titre']) or 'Match pour la troisième place') .. '</strong>'
						.. '</div></div>'
			wikiTable[94] = '\n|colspan="' .. (9 + 2 * nSet) .. '"|'
						.. date_duration (pargs, nSetFinal2, 'DP1', 6 + nSet)
	-- DP1
			match = matchPrep (pargs, nSetFinal2, argMatch(32), 'DP1', 'DP2', sport, 5 + nSet)
			wikiTable[96] = '\n|rowspan="4" colspan="' .. (10 + 2 * nSet) .. '"|'
						.. match[1]
			wikiTable[97] = '\n|rowspan="2" colspan="' .. (2 + nSet) .. '"|'
			wikiTable[98] = match[2]
		end

		-- Définition des hauteur de ligne (sensible sur Firefox) pour regrouper les matchs du premier tour par 2
		-- Si le le premier "joueur" contient <br /> la hauteur des cellules est plus importante.
		addCellsHeight (pargs, wikiTable, 'DS')

		wikiText = '\n|- \n|'
	return ligneTitre .. table.concat (wikiTable, wikiText)
end


return z