La documentation pour ce module peut être créée à Module:Section/Documentation

-- Permet de récupérer ou de regrouper des section à l’intérieur de pages 
-- du même livre ou de pages dont on a fourni le(s) titre(s) en argument
-- Variantes :
-- {{#invoke:Section|section|page=#page seulement|section=nom de la section à récupérer}}
-- {{#invoke:Section|section|titre = titre de la page incluant le ns|section=nom de la section}}
-- {{#invoke:Section|section|titre 1|section 1|titre 2|section 2| etc}}
-- {{#invoke:Section|section|AAAXXX-YYY}} ou {{#invoke:Section|section|section=AAAXXX-YYY}}
-- où AAAXXX-YYY est le nom de la section qu’on retrouve sur le page XXX et YYY
-- permet de reconstruire un modèle qui débute sur une page et se termine sur la suivante
-- args['pre'] : préfixe à insérer avant les sections
-- args['suf'] : suffixe à insérer après les 

local p = {}
local args

function p.section(frame)

	parentFrame = frame:getParent()
    args = parentFrame.args
    local textesection = ""
    local nopage
    local index
    local section

    if not args["section"] and frame.args["section"] then
		args = frame.args
    elseif not args[1] and frame.args[1] then 
		args = frame.args
    end
    
    nopage = args["page"]
    cible = args["titre"]
    
    if args[2] == nil then 
	    if cible == nil then
	        titre  = mw.title.getCurrentTitle()
	        ns     = titre.nsText
	        if ns == "" then --récupération de l’index dans l’espace principal 
	        	texte = titre.getContent(titre)
	        	index = mw.ustring.match( texte, 'index%="(.-)"')
	        else
	        	index =	titre.baseText
	        end	    	
	    	
		    if nopage ~= nil then
		    	nopage = mw.text.trim(nopage)

			    cible = "Page:".. index .. "/" .. nopage
			    args[1] = cible
			    args[2] = args['section'] 
			    
		    else
				args[2] = args[1] or args['section']
				section = true
				args[4] = args[2]
				pages = getPages(args[2])
				args[1] = "Page:".. index .. "/" .. pages[1]
				args[3] = "Page:".. index .. "/" .. pages[2]
		    end
		else 
			args[1] = cible	 
			args[2] = args['section']
	    end
    end

	if args['section'] == nil or section then
		if table.maxn( args ) == 0 then 
			for i, v in ipairs(args) do
			    if i % 2 ~= 0 then
			    	textesection = textesection .. getSection(v, args[i + 1])
			    end
			end
		else
			for n = 1, table.maxn( args ), 2 do
				textesection = textesection .. getSection(args[n], args[n + 1])
			end
		end
		
	else 
		textesection = getSection(args[1], args[2])
	end
	
	textesection = (args['pre'] or '') .. textesection .. (args['suf'] or '')

return frame:preprocess(textesection)
--return (args[1] or '') .. '\n\n' .. (args[2] or '') .. '\n\n' .. (args[3] or '')  .. '\n\n' .. (args[4] or '')
--return table.maxn( args )
--return args['section']

end	

function getSection(cible, section)
	local str = ''
	titre = mw.title.new(cible)
    texte = titre.getContent(titre)
    if texte then
    		--ajouter % devant tout caractère magique dans le nom de la section 
		section = mw.ustring.gsub(section, '([%^%$%(%)%%%.%*%+%-%?])', '%%' .. '%1')
    	str = mw.ustring.match( texte, '<section begin="' .. section .. '" -/>' .. '(.-)<section end="' .. section .. '" -/>')
    end	
	return str
end

-- Obtenir les 2 nos de pages incrustés dans le nom de la section
function getPages(str)
	local pages = {}
	for c1, c2 in mw.ustring.gmatch( str, '%-([0-9]*)%-([0-9]*)') do
	    pages[1] = c1
	    pages[2] = c2
    end
	return pages
end

return p