Modulo:Vedi anche: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
aggiunta categoria |
uniformo i template hatnote col template:Avviso permanente |
||
(22 versioni intermedie di 6 utenti non mostrate) | |||
Riga 1:
--[[
* Modulo che implementa il template {{Vedi anche}}.
]]
require('
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne
local p = {}▼
--
-- @param {string} arg
▲-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne ritorna il wikilink.
-- @return {string}
local function parseArg(arg)
local dest, count, obj, content
-- restituisce errore con wikilink a categorie
if arg:match('^%s*:%s*[Cc][Aa][Tt]') then
return '<span class="error">(usare il [[Template:Vedi categoria]])</span>'
end
-- rimuove eventuali pipe inserite tramite {{!}}
arg = arg:match('(.
-- sostituisce le HTML entity (per esempio '
arg =
-- crea oggetto per il titolo
-- sostituisce # con §▼
▲ -- sostituisce # con §, se trovato crea un piped wikilink
dest = arg
arg, count = arg:gsub('#', ' § ')
dest = count == 1 and (dest .. '|') or ''
-- converte la prima lettera in maiuscola o minuscola a seconda che la voce contenga il template Titolo minuscolo
content = obj and obj:getContent()
if content and content:match('{{%s*[Tt]itolo minuscolo%s*[|}]') then
arg = mw.getContentLanguage():lcfirst(arg)
else
arg = mw.getContentLanguage():ucfirst(arg)
end
return string.format("'''[[%s%s]]'''", dest, arg)
end
-- Costruisce l'HTML per contenere i wikilink alle pagine.
--
-- @param {string} wikitext
-- @return {string}
local function buildHTML(wikitext)
return mw.getCurrentFrame():extensionTag{
args = {
src = 'Modulo:Vedi anche/styles.css'
}
} .. mw.getCurrentFrame():expandTemplate{
title = 'Avviso permanente',
args = {
immagine = 'Magnifying glass icon mgx2.svg',
}
}
▲ :wikitext("''Lo stesso argomento in dettaglio: " .. wikitext .. "''.")
end
-- =============================================================================
-- entry-point per {{Vedi anche}}▼
-- Funzioni esportate
-- =============================================================================
▲local p = {}
function p.main(frame)
local lastArg, conjunction
local args = {}
for _, val in ipairs(frame:getParent().args) do
if mw.text.trim(val) ~= '' then
table.insert(args, parseArg(val))
lastArg = val
end
end
if #args > 1 and lastArg then
conjunction = mw.ustring.lower(lastArg:sub(1, 1)) == 'e' and 'ed' or 'e'
conjunction = ' ' .. conjunction .. ' '
end
▲ return buildHTML(mw.text.listToText(args, ', ', ' e ')) .. cat
end
|