Utilisateur:Alex brollo/sandbox/Module:Table

La bibliothèque libre.

-- 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 )

   local args = frame.args
   local not_nodots = args[1] == nil or mw.text.trim( args[1] ) ~= 'nodots'
    -- Conteneur général (relatif, et à fond non transparent) de positionnement de la table 

local text = string.format( '

' -- Fin de l'ouverture du div externe
   -- TDM : Conteneur avec section+titre+page (seulement nécessaire si numéro de page)
   if args.page and args.page ~=  then
text = text .. string.format( '
', out_arg( args.largeurp, "0" ) )
       -- GAUCHE+CENTRE: Conteneur flottant à gauche avec section+titre (seulement nécessaire si numéro de page)
text = text .. '
'
   end
   -- GAUCHE: Conteneur flottant à gauche du numéro de section (non transparent si pointillés)
   if args.section and args.section ~=  then
text = text .. string.format( '
',
                                     out_arg( args.largeurs, 45), out_arg( args.aligns, 'right') )
       if not_nodots then
           text = text .. string.format('', out_arg( args.couleur_fond, '#FFFFFF' ) )
       end
       text = text .. args.section .. ' '
       if not_nodots then
           text = text .. ''
       end
text = text .. '
'
       -- CENTRE: Conteneur du titre et des pointillés 
text = text .. string.format( '
', out_arg(args.largeurs, 45) )
   end
   -- Conteneur interne optionnel pour gérer la marge d’indentation négative
   if tonumber( out_arg(args.indentation, 0 ) ) < 0 then
text = text .. string.format( '
',
                                     -args.indentation, out_arg(args.indentation_unit, "em"), args.indentation, out_arg(args.indentation_unit, "em" ) )
   end
   -- Le titre lui-même (justifiable, indentable), en haut du conteneur CENTRE (non transparent si pointillés)
text = text .. '
0 then
       text = text .. string.format( 'text-indent:%s%s', args.indentation, out_arg(args.indentation_unit, "em" ) )
   end
   text = text .. '">'
   if not_nodots then
        text = text .. string.format('', out_arg( args.couleur_fond, '#FFFFFF' ) )
   end
   text = text .. out_arg(args.titre,  )
   if not_nodots then
       text = text .. ' '
   end
text = text .. '
'
   -- Fin du conteneur interne optionnel pour gérer la marge d’indentation négative
   if tonumber( out_arg(args.indentation, 0 ) ) < 0 then
text = text .. '
'
   end
   -- Les pointillés éventuels (superposés en bas, nécessite un positionnement absolu dans le conteneur CENTRE)
   if not_nodots then
text = text .. '
', math.abs( tonumber( out_arg( args.indentation, "0" ) ) ) + 1, out_arg( args.indentation_unit, "em" ) ) text = text .. '
' text = text .. '
'
   end
   -- CENTRE: Fin du conteneur du titre et des pointillés
   if args.section and args.section ~=  then
text = text .. '
'
       -- Étend le flottant à gauche verticalement (le numéro de section)
text = text .. '
'
   end
   if args.page and args.page ~=  then
       -- GAUCHE+CENTRE: Fin du conteneur avec section+titre (seulement nécessaire si numéro de page)
text = text .. '
'
       -- DROITE: Conteneur flottant à droite du numéro de page (seulement nécessaire si numéro de page)
text = text .. '
'
       -- Le numéro, insécable, est positionné verticalement en bas dans le flottant (non transparent si pointillés)
text = text .. '
'
       if not_nodots then
           text = text .. string.format('', out_arg( args.couleur_fond, '#FFFFFF' ) )
           -- seulement pour éviter de coller aux pointillés
           text = text .. ' '
       end
       text = text .. args.page
       if not_nodots then
           text = text .. ''
       end
text = text .. '
'
       -- DROITE: Fin du conteneur du flottant du numéro de page (seulement nécessaire si numéro de page)
text = text .. '
'
       -- Étend le flottant à droite verticalement (pour descendre le numéro de page)
text = text .. '
'
       -- TDM :Fin du conteneur avec section+titre+page (seulement nécessaire si numéro de page)
text = text .. '
'
   end
   -- EXTERNE: Fin du conteneur
text = text .. '

'

   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 ) ) .. '

' .. table( frame )

end

function p.table( frame )

   return table( frame:getParent() )

end

return p