Module:Nom dynastique
Ce module est utilisé par les modèles {{Souverain2}}, {{Souverain3}} et {{Souverain-}}.
Utilisation
Fonctions exportables :
fonction(frame)
– description (courte description defonction(frame)
et autres informations pertinentes).fonction2()
– description2 (courte description defonction2()
et autres informations pertinentes).
Autres fonctions :
fonction()
– description2 (courte description defonction()
et autres informations pertinentes).
Modules externes et autres éléments dont ce module a besoin pour fonctionner :
mw.title
– description (courte description expliquant la dépendance de ce module externe).
Exemples
Pour des exemples, voir la page de test permettant de tester diverses modifications apportées.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}local Outils = require( 'Module:Outils' )local trim = Outils.trimlocal Romains = require('Module:Chiffres romains')local conversion = Romains.conversion-- Ce booléen permet d'indiquer si on doit prendre le complément du lien pour l'afficher (exemple : "Louis Ier d'Italie"); c'est le cas-- de l'appel par le modèle Souverain3local afficher_le_complement = falselocal typenom = '[%C]+'local function trouveRomain(chaine)local test = ' ' .. chaine .. ' 'local positionDebut, _, quantieme = string.find(test, ' ([IVXLCDM]+),? ')if not positionDebut thenpositionDebut, _, quantieme = string.find(test, ' (Ier),? ')endif not positionDebut thenpositionDebut, _, quantieme = string.find(test, ' (Ire),? ')endif positionDebut thenreturn positionDebut, positionDebut + string.len(quantieme) - 1, quantiemeelsereturn nil, nil, nilendend-- Extraction d'une chaîne, on recherche si c'est de la forme : "nom" "chiffres romains" "complément"-- En retour, le premier paramètre indique s'il y a présence d'un nombre en chiffres romainsfunction p.chaine(chaine)local function extraction_elements(chaine)local positionDebut, positionFin, quantieme = trouveRomain(chaine)if not positionDebut thenreturn false, '', '', ''endlocal nom = string.sub(chaine, 1, positionDebut - 2)local complement = ''if positionFin < string.len(chaine) thencomplement = trim(string.sub(chaine, positionFin + 1))endreturn true, nom, quantieme, complementend-- Si le paramètre passé n'existe pas, retourif not chaine or chaine == '' thenreturn false, '<span class="error">Aucun paramètre</span>'endlocal presence_romain, nom, quantieme, complement = extraction_elements(chaine)return true, '', presence_romain, nom, quantieme, complementendfunction p.surnom(chaine)local presence_italiques, presence_guillemets, presence_dit, presence_virgule = false, false, false, falseif mw.ustring.match(chaine, "''") thenpresence_italiques = truechaine = mw.ustring.gsub(chaine, "''", "")endif mw.ustring.match(chaine, '«') thenpresence_guillemets = truechaine = mw.ustring.gsub(chaine, '« ', '')chaine = mw.ustring.gsub(chaine, '«', '')endif mw.ustring.match(chaine, '»') thenpresence_guillemets = truechaine = mw.ustring.gsub(chaine, ' »', '')chaine = mw.ustring.gsub(chaine, '»', '')endif mw.ustring.match(chaine, ' dite? ') or (mw.ustring.sub(chaine, 1, 4) == 'dit ') or (mw.ustring.sub(chaine, 1, 5) == 'dite ') thenpresence_dit = truechaine = mw.ustring.gsub(chaine, 'dit ', '')chaine = mw.ustring.gsub(chaine, 'dite ', '')endif presence_italiques or presence_guillemets or presence_dit thenif mw.ustring.match(chaine, ', ') thenpresence_virgule = truechaine = mw.ustring.gsub(chaine, ', ', ' ')endendreturn chaine, presence_italiques, presence_guillemets, presence_dit, presence_virguleendfunction p.nettoyage(chaine)-- remplacement des espaces insécablesif chaine thenchaine = chaine-- nbsp:gsub( '\194\160', ' ' ):gsub( ' ', ' ' ):gsub( ' ', ' ' )-- narrow nbsp:gsub( '\226\128\175', ' ' ):gsub( ' ', ' ' )-- thin space:gsub( '\226\128\137', ' ' ):gsub( ' ', ' ' ):gsub( ' ', ' ' )-- simple space:gsub( ' ', ' ' )endreturn chaineend-- Mise en forme, traitement des donneésfunction p.traitement(a1, a2, a3, a4)local test = truelocal message = ''local lien = ''local nom = ''local quantieme = ''local complement = ''local nom_affiche = ''local quantieme_affiche = ''local complement_affiche = ''local presence_romains, presence_italiques, presence_guillemetsa1 = p.nettoyage(a1)a2 = p.nettoyage(a2)a3 = p.nettoyage(a3)a4 = p.nettoyage(a4)-- Si le premier paramètre n'existe pas, retourif (a1 == '') and (a2 == '') thenreturn false, '<span class="error">Paramètres absents</span>'end-- Test de présence d'un deuxième paramètreif a2 and a2 ~= '' then-- Cas où il y a au moins deux paramètresif string.match(a2, '^[IVXLCDM]+$') or a2 == 'Ier' or a2 == 'Ire' then-- Si le deuxième paramètre est un nombre en chiffres romains, on est dans le cas de :--{{Souverain|Louis|XIV|(roi de France)|, le Roi Soleil}} et similairesnom = a1nom_affiche = a1quantieme = a2test, message, quantieme_affiche = p.typo(quantieme)if not test then return test, message endlien = nom..' '..quantiemecomplement = ''if a3 thencomplement = a3if string.len(complement) > 0 thenlien = lien..' '..p.surnom(complement)endendif not a4 then a4 ='' endif a4 == '' thenif a3 and afficher_le_complement thencomplement_affiche = a3endelsecomplement_affiche = a4endelse-- Si le deuxième paramètre n'est pas un nombre en chiffres romains, soit il y a une erreur,-- soit on est dans le cas de :--{{Souverain|Louis XIV (roi de France)|, le Roi Soleil}} et similaires--ou {{Souverain|René II d'Anjou|René III de Poitiers}}--Il faut qu'il y ait un nombre romain dans au moins un des deuxlien = a1-- On vérifie d'abord si complément contient un texte à mettre en forme, auquel cas il s'impose sur le libellé du lientest, message, presence_romains, nom, quantieme, complement = p.chaine(a2)if not test then return test, message endif presence_romains thentest, message, quantieme_affiche = p.typo(quantieme)if not test then return test, message endnom_affiche = nomif complement thencomplement_affiche = complementendelsetest, message, presence_romains, nom, quantieme, complement = p.chaine(a1)if not test then return test, message endnom_affiche = nomif presence_romains thentest, message, quantieme_affiche = p.typo(quantieme)if not test then return test, message endcomplement_affiche = a2elsetest = falsemessage = '<span class="error">Un nombre en chiffres romains est requis</span>'endendendelse-- Si le deuxième paramètre n'existe pas, on est dans le cas de : {{Souverain|Louis XIV de France}} et similairestest, message, presence_romains, nom, quantieme, complement = p.chaine(a1)if not test then return test, message endlien = a1if presence_romains thennom_affiche = nomtest, message, quantieme_affiche = p.typo(quantieme)if not test then return test, message endendlien, presence_italiques, presence_guillemets = p.surnom(lien)if afficher_le_complement == true thenif trim(complement) thencomplement_affiche = trim(complement)elseif (presence_italiques or presence_guillemets) and not presence_romains thencomplement_affiche = a1elseafficher_le_complement = falseendendendendreturn test, message, lien, nom_affiche, quantieme_affiche, complement_afficheendfunction p.typo(quantieme)local test = truelocal message = ''-- Mise en forme typographique : éventuelle infobulle et éventuel exposant à partir du chiffre romain envoyé-- On obtient le "quantième affiché"-- On teste d'abord si on a une chaine de la forme "Ier" ou "Ire"local test1 = 'non'if string.len(quantieme) > 2 thentest1 = string.sub(quantieme, -2)end-- émulation des modèles {{Ire}}, {{III}}local infobulle = ''local exposant = 'non'local numero = ''local fin = ''local quantieme_affiche = ''if (test1 == 're') or (test1 == 'er') thenif test1 == 're' thenexposant = '<sup>re</sup>'infobulle = 'première'elseexposant = '<sup>er</sup>'infobulle = "premier"endquantieme = 'I'..test1numero = 'I'fin = '</span>'..exposant..'</abbr>'elsequantieme = string.upper(quantieme)test, message, infobulle = conversion(quantieme)if not test then return test, message, '' endnumero = quantiemefin = '</span></abbr>'endif infobulle == ''theninfobulle = 'inconnu'endquantieme_affiche = '<abbr class="abbr" title="'..infobulle..'" ><span class="romain" style="text-transform:uppercase">'..numero..finreturn test, message, quantieme_afficheendfunction p.typo_complement(chaine)if chaine thenif string.len(chaine) > 0 then-- si le complement affiché (", le Roi Soleil" dans le cas de Louis XIV) commence par une virgule, on ne met pas d'espace avant,-- mais on vérifie qu'il y a bien une espace entre la virgule et le mot suivantif not (string.sub(chaine, 1, 1) == ',') thenchaine = ' '..chaineend-- S'il y a des guillemets, on compense le bug qui empêche la gestion correcte des insécables dans un lien wikiif mw.ustring.match(chaine, '« '..typenom..' »') thenchaine = mw.ustring.gsub(chaine, '« ', '« ')chaine = mw.ustring.gsub(chaine, ' »', ' »')endendendreturn true, '', chaineend-- Fonction de mise en forme du lien à afficher-- de la forme [[lien | "nom affiché" "quantième affiché" "complément affiché" ]], les éléments de la partie droite sont optionnelsfunction p.ecriture_avec_lien(lien, nom_affiche, quantieme_affiche, complement_affiche)local test = truelocal texte1 = ''local test, message, complement_affiche2 = p.typo_complement(complement_affiche)texte1 = '[['..lienif nom_affiche thenif string.len(nom_affiche) > 0 thenif string.len(quantieme_affiche) > 0 then-- S'il y a un nombre, ajout d'un "nowrap" pour l'espace insécabletexte1 = texte1..'|<span class="nowrap">'..nom_affiche..' '..quantieme_affiche..'</span>'if complement_affiche2thenif string.len(complement_affiche2) > 0 thentexte1 = texte1..complement_affiche2endendelsetexte1 = texte1..'|'..nom_afficheif string.len(complement_affiche2) > 0 thentexte1 = texte1..complement_affiche2endendendelseif complement_affiche2 thenif string.len(complement_affiche2) > 0 thentexte1 = texte1..'|'..trim(complement_affiche2)endendendtexte1 = texte1.."]]"return test, message, texte1endfunction p.ecriture_sans_lien(lien, nom_affiche, quantieme_affiche, complement_affiche)local test = truelocal message = ''local texte1 = ''local test, message, complement_affiche2 = p.typo_complement(complement_affiche)if quantieme_affiche and nom_affiche thenif (string.len(nom_affiche) > 0) thenif string.len(quantieme_affiche) > 0 then-- S'il y a un nombre, ajout d'un "nowrap" pour l'espace insécabletexte1 = texte1..'<span class="nowrap">'..nom_affiche..' '..quantieme_affiche..'</span>'if complement_affiche2 thentexte1 = texte1..complement_affiche2endelseif complement_affiche2 thentexte1 = texte1..nom_affiche..complement_affiche2endendelsetexte1 = texte1..quantieme_afficheif complement_affiche2 thentexte1 = texte1..complement_affiche2endendelseif complement_affiche2 thenif string.len(complement_affiche2) > 0 thentexte1 = texte1..trim(complement_affiche2)endendendif texte1 == '' thentexte1 = lienendreturn test, message, texte1end-- Affichage dans le cas général (émule le modèle Souverain2)function p.Souverain2(frame)local args = Outils.extractArgs( frame )local arg1 = trim(args[1]) or ''local arg2 = trim(args[2]) or ''local arg3 = trim(args[3]) or ''local arg4 = trim(args[4]) or ''local test, message, t1, t2, t3, t4 = p.traitement(arg1, arg2, arg3, arg4)if not test thenreturn messageendlocal test, message, texte = p.ecriture_avec_lien(t1, t2, t3, t4)if not test thenreturn messageelsereturn texteendend-- Affichage dans le cas où le lien est de la forme [[Charles V le Sage|{{nobr|Charles V}} le Sage]]-- correspond au modèle Souverain3, ce qui permet d'écrire :-- {{Souverain3|Charles V le Sage}}-- plutôt que :-- {{Souverain2|Charles V le Sage|le Sage}}-- (émule le modèle Souverain3)function p.Souverain3(frame)local args = Outils.extractArgs( frame )local a1 = trim(args[1]) or ''local a2 = trim(args[2]) or ''local a3 = trim(args[3]) or ''local a4 = trim(args[4]) or ''afficher_le_complement = truelocal test, message, t1, t2, t3, t4 = p.traitement(a1, a2, a3)if not test thenreturn messageendlocal test, message, texte = p.ecriture_avec_lien(t1, t2, t3, t4)if not test thenreturn messageelsereturn texteendend-- Affichage dans le cas où on veut une mise en forme correspndant à {{nobr|Charles {{V}}}} ou {{nobr|Louis {{Ier}}}}-- Aucune mise en forme s'il n'y a pas un nombre en chiffres romains-- (correspond au modèle Souverain-)function p.Souverain_sans_lien(frame)local args = Outils.extractArgs( frame )local a1 = trim(args[1]) or ''local a2 = trim(args[2]) or ''local a3 = trim(args[3]) or ''local a4 = trim(args[4]) or ''afficher_le_complement = falselocal test, message, t1, t2, t3, t4 = p.traitement(a1, a2, a3, a4)if not test thenreturn messageendlocal test, message, texte = p.ecriture_sans_lien(t1, t2, t3, t4)if not test thenreturn messageelsereturn texteendendreturn p
🔥 Top keywords: Wikipédia:Accueil principalListe de sondages sur les élections législatives françaises de 2024Spécial:RechercheJordan BardellaChampionnat d'Europe de football 2024N'Golo KantéJodie DevosKylian MbappéÉlections législatives françaises de 2024Marcus ThuramLe Jardin des Finzi-Contini (film)Maria Schneider (actrice)Cookie (informatique)Championnat d'Europe de footballNouveau Front populaireKevin DansoAntoine GriezmannÉric CiottiChampionnat d'Europe de football 2020Dominique SandaMike MaignanWilliam SalibaLionel JospinÉlections législatives de 2024 dans l'EssonneFront populaire (France)Françoise HardyÉlections législatives de 2024 à ParisRassemblement nationalJean-Luc MélenchonFichier:Cleopatra poster.jpgOlivier GiroudSébastien ChenuDidier DeschampsLa Chronique des BridgertonÉlections législatives de 2024 dans les YvelinesLilian ThuramListe de partis politiques en FranceAnne SinclairGabriel Attal