La documentazione per questo modulo può essere creata in Modulo:VoceIndice/man

-- Code dérivé des modèles table et table2 par Verdy_p et Faager, toute divergence dans le code ou le comportement est un bug.
function table( frame, frame_0 )

    local args = frame.args
	local sep='<span class="voceindice-sep">|||</span>'
    local not_nodots = args[1] == nil or string.find( args[1],"nodots") == nil

     -- Conteneur général (relatif, et à fond non transparent) de positionnement de la table.
     -- The first div tag into local text fixes the "flex issue". 
    local text = string.format( '<div>'..'<div class="voceindice-riga" style="margin:%s auto;',
                                 out_arg( args.espace, ".125em" ) )
    if args.align == 'left' or args.align == 'right' then
        text = text .. string.format('margin-%s:0;', args.align)
    end

    if args.larghezza and args.larghezza ~= '' then
        text = text .. string.format('width:%s;', args.larghezza)
    end

    if args.couleur_fond and args.couleur_fond ~= '' then
        text = text .. string.format('background:%s;', args.couleur_fond)
    elseif not_nodots then
        text = text .. 'background:#FFFFFF;'
    end

    if args.couleur and args.couleur ~= '' then
        text = text .. string.format('color:%s;', args.couleur)
    elseif not_nodots then
        text = text .. 'color:#000000;'
    end

    -- zoom pour forcer hasLayout (bogue IE6 des marges)
    text = text .. 'line-height:1.5em;zoom:1">' -- Fin de l'ouverture du div externe

    -- TDM : Conteneur avec sezione+titolo+pagina (seulement nécessaire si numéro de pagina)
    if args.pagina and args.pagina ~= '' then
        text = text .. string.format( '<div style="margin-right:%spx">', out_arg( args.larghezzap, "0" ) )
        -- GAUCHE+CENTRE: Conteneur flottant à gauche avec sezione+titolo (seulement nécessaire si numéro de pagina)
        text = text .. '<div style="float:left;width:100%">'
    end

    -- GAUCHE: Conteneur flottant à gauche du numéro de sezione (non transparent si pointillés)
    if args.sezione and args.sezione ~= '' then
        text = text .. string.format( '<div style="float:left;z-index:2;min-width:%spx;text-indent:0;text-align:%s;white-space:nowrap">',
           out_arg( args.larghezzas, 45), out_arg( args.aligns, 'right') )

        if not_nodots then
            text = text .. string.format('<span style="background:%s">', out_arg( args.couleur_fond, '#FFFFFF' ) )
        end
        text = text .. args.sezione .. '&nbsp;'
        if not_nodots then
            text = text .. '</span>'
        end
        text = text .. sep..'</div>'

        -- CENTRE: Conteneur du titolo et des pointillés 
        text = text .. string.format( '<div style="position:relative;margin-left:%spx">', out_arg(args.larghezzas, 45) )
    end

    -- Conteneur interne optionnel pour gérer la marge d’indentazione négative
    if tonumber( out_arg(args.indentazione, 0 ) ) < 0 then
        text = text .. string.format( '<div style="margin-left:%s%s;text-indent:%s%s">',
                                      -args.indentazione, out_arg(args.indentazione_unit, "em"), args.indentazione, out_arg(args.indentazione_unit, "em" ) )
    end

    -- Le titolo lui-même (justifiable, indentable), en haut du conteneur CENTRE (non transparent si pointillés)
    text = text .. '<div style="position:relative;z-index:2;'
    text = text .. string.format( 'text-align:%s;', out_arg( args.text_align, 'justify' ) )
    if tonumber( out_arg(args.indentazione, 0 ) ) > 0 then
        text = text .. string.format( 'text-indent:%s%s', args.indentazione, out_arg(args.indentazione_unit, "em" ) )
    end
    text = text .. '">'
    if not_nodots then
         text = text .. string.format('<span style="background:%s">', out_arg( args.couleur_fond, '#FFFFFF' ) )
    end
    text = text .. '<span class="voceindice-titolo">'..out_arg(args.titolo, '' )..'</span>'
    if not_nodots then
        text = text .. '&nbsp;</span>'
    end
    text = text .. sep..'</div>'

    -- Fin du conteneur interne optionnel pour gérer la marge d’indentazione négative
    if tonumber( out_arg(args.indentazione, 0 ) ) < 0 then
        text = text  .. '</div>'
    end

    -- Les pointillés éventuels (superposés en bas, nécessite un positionnement absolu dans le conteneur CENTRE)
    if not_nodots then
        text = text .. '<div class="ws-noexport" style="position:relative;'
        text = text .. string.format( 'margin-left:%d%s">', math.abs( tonumber( out_arg( args.indentazione, "0" ) ) ) + 1, out_arg( args.indentazione_unit, "em" ) )
        text = text .. '<div style="position:absolute;z-index:1;bottom:.3em;width:100%;border-bottom:0.135em dotted '
        text = text .. out_arg( args.couleur, '#000000' ) .. '"></div>'
        text = text .. '</div>'
    end

    -- CENTRE: Fin du conteneur du titolo et des pointillés
    if args.sezione and args.sezione ~= '' then
        text = text .. '</div>'
        -- Étend le flottant à gauche verticalement (le numéro de sezione)
        text = text .. '<div class="ws-noexport" style="clear:both"></div>'
    end

    if args.pagina and args.pagina ~= '' then
        -- qui inserire normalizzazione args.pagina
    		
		if string.find(args.pagina," ")~=nil then
    		-- elimino eventuali &nbsp;
    		args.pagina=string.gsub(args.pagina,"&nbsp;","")
    		
    		if string.find(args.pagina,"»")==1 or string.find(args.pagina,"„")==1  then
    		 	args.pagina="&nbsp;&nbsp;"..args.pagina
    		end
    		-- verifica che un eventuale spazio non cada dopo un inizio di tag html o di link
    		if args.larghezzap==nil or args.larghezzap*1<50 then args.larghezzap=50 end
    		local ps=string.find(args.pagina," ")
    		local cs1=string.find(args.pagina,"<")
    		if cs1==nil then cs1=1000 end
    		local cs2=string.find(args.pagina,"%[%[")
    		if cs2==nil then cs2=1000 end
    		if  ps<cs1 and ps<cs2 then
    			args.pagina=string.format('<span style="float:left;background:%s">',out_arg( args.couleur_fond, '#FFFFFF' ))..string.sub(args.pagina,1,ps-1)..'</span>'..' <span class="voceindice-pagina">'..string.sub(args.pagina,ps+1)..'</span>'
    		else
    			args.pagina='<span class="voceindice-pagina">'..args.pagina..'</span>'
    		end
		else args.pagina='<span class="voceindice-pagina">'..args.pagina..'</span>'
		end
        
        
        -- GAUCHE+CENTRE: Fin du conteneur avec sezione+titolo (seulement nécessaire si numéro de pagina)
        text = text .. '</div>'
        -- DROITE: Conteneur flottant à droite du numéro de pagina (seulement nécessaire si numéro de pagina)
        text = text .. '<div class="ws-noexport" style="float:right">'
        -- Le numéro, insécable, est positionné verticalement en bas dans le flottant (non transparent si pointillés)
        if out_arg( args.bb, '0' )=='0' then
        	text = text .. '<div style="position:absolute;z-index:2;min-width:'..(out_arg( args.larghezzap, '0' )-10)..'px;bottom:0;right:0;text-indent:0;text-align:right;background:#FFFFFF">' -- white-space:nowrap">'
        else
        	text = text .. '<div style="position:absolute;z-index:2;min-width:'..(out_arg( args.larghezzap, '0' )-10)..'px;bottom:0;right:0;text-indent:0;text-align:right;background:#FFFFFF; border-bottom:1px solid black;">' -- white-space:nowrap">'
        end
        if not_nodots then
            text = text .. string.format('<span style="background:%s">', out_arg( args.couleur_fond, '#FFFFFF' ) )
            -- seulement pour éviter de coller aux pointillés
            text = text .. '&nbsp;'
        end

		
        text = text .. args.pagina
        if not_nodots then
            text = text .. '</span>'
        end
        text = text .. '</div>'
        -- DROITE: Fin du conteneur du flottant du numéro de pagina (seulement nécessaire si numéro de pagina)
        text = text .. '</div>'

        -- Étend le flottant à droite verticalement (pour descendre le numéro de pagina)
        text = text .. '<div class="ws-noexport" style="clear:both"></div>'

        -- TDM :Fin du conteneur avec sezione+titolo+pagina (seulement nécessaire si numéro de pagina)
        text = text .. '</div>'
    end

    -- EXTERNE: Fin du conteneur
    text = text .. '</div>\n</div>'

    return text
end

function out_arg( arg, default )
    if arg and arg ~= '' then
        return arg
    end
    return default
end

local p = {}

-- Aide au debuggage, retourne le code généré sous forme d'une chaîne de caractères encodé
-- et sous forme de html.
function p.table_as_string( frame )
    return mw.text.encode( table( frame ) ) .. '<div style="clear:both"></div>' .. table( frame )
end
 
function p.voceIndice( frame )
	-- passo alla funzione il frame parent e il frame
    return table( frame:getParent(),frame )
end
 
return p