Aller au contenu

Module:Format petscan

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 28 mars 2018 à 19:07 et modifiée en dernier par TomT0m (discuter | contributions). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.

 Documentation[créer] [purger]
local p = {}


p.format_paste = function(frame)
	local petscan_text = frame.args[1]
	local tmpl = frame.args[2]
	local newline = ( frame.args["pasretour"] and false ) or true
	
	local format_func 
	
	if tmpl and tmpl ~= "" then
		format_func = function(qid) 
			return frame:expandTemplate{
				title=tmpl, 
				args = {qid} 
			}
		end
	else
		format_func = function(qid) return "* " .."[[" .. mw.wikibase.label(qid) .. "]] " .. "[[:d:" .. qid .. "|(d)]]" end
	end
	local res = ""
	for match in string.gmatch(petscan_text, "[[]Q[0-9]+[]]") do
		local qid = match:sub(2, #match - 1)
		res = res ..
		tostring(format_func(qid)) .. 
		((newline and "\n") or "") --sous optimal de concaténer comme ça dans une boucle mais c’est pas trop grave
		-- if 
	end	
	return res
end

return p