Modulo:Vedi anche/sandbox
--[[
* Modulo che implementa il template {{Vedi anche}}.
]]
require('strict')
-- Parsifica un argomento del template (rappresenta il titolo di una pagina) e ne restituisce il wikilink.
--
-- @param {string} arg
-- @return {string}
local function parseArg(arg)
local dest, count
-- 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('(.*)|') or arg
-- sostituisce le HTML entity (per esempio ' generato da {{PAGENAME}} quando il titolo contiene l'apostrofo)
arg = mw.text.decode(arg)
-- sostituisce # con §, se trovato crea un piped wikilink
dest = arg
arg, count = arg:gsub('#', ' § ')
dest = count == 1 and (dest .. '|') or ''
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)
local tableNode = mw.html.create('table')
tableNode
:addClass('vedi-anche noprint')
:tag('tr')
:tag('td')
:wikitext('[[File:Magnifying glass icon mgx2.svg|20px|class=noviewer|link=|alt=]]')
:done()
:tag('td')
:wikitext(string.format("''Lo stesso argomento in dettaglio: %s''.", wikitext))
:done()
return tostring(tableNode)
end
-- =============================================================================
-- Funzioni esportate
-- =============================================================================
local p = {}
-- Funzione per il template {{Vedi anche}}.
function p.main(frame)
local lastArg, conjunction
local styles = 'Modulo:Vedi anche/sandbox/styles.css'
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 frame:extensionTag{
name = 'templatestyles',
args = {src = styles}
} .. buildHTML(mw.text.listToText(args, ', ', conjunction))
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.