Module:Link Label
| Main | Documentation | Usage |
This module implements {{Tt}}.
local p = {}
local lib = require('Module:Feature')
local TERMS = {
' %(Quest%)',
' %(Chapter%)',
' %(Act%)',
' %(Archon Quest%)',
' %(Story Quest%)',
' %(World Quest%)',
' %(Hangout Event%)',
' %(Event Quest%)',
' %(Event Chapter%)',
' %(Event Act%)',
' %(Commission%)',
' %(Soundtrack%)',
' %(Album%)',
' %(Event%)',
' %(NPC%)',
' %(Furnishing%)',
' %(Subarea%)',
' %(Area%)',
' %(Subregion%)',
' %(Domain%)',
' %(Quest Domain%)',
' %(Instance%)',
' %(Footprint%)',
' %(Character Card%)',
' %(Character Card Skill%)',
' %(Event Card%)',
' %(Equipment Card%)',
' %(Material%)',
}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
wrapper = { 'Template:Link Label' }
})
return p._main(args)
end
function p.getTerms()
local result = mw.html.create()
for _, term in ipairs(TERMS) do
local replacedTerm, _ = term:gsub('%%', '')
result:newline():wikitext('* '):tag('code'):wikitext(replacedTerm):done()
end
return result
end
function p._main(args)
local link = type(args) == 'table' and args[1] or args
local suffix = ''
if (link == nil or type(link) == 'table') then return '' end
link = tostring(link)
if (link:find('%|')) then return link end
-- if link contains multiple links
local _, count = link:gsub('%[%[', '')
if (count > 1) then return link end
if (link:find('%[%[') and link:find('%]%]')) then
link = link:gsub('%[%[', ''):gsub('%]%]', '')
end
local label = link
for _, term in ipairs(TERMS) do
if (link:find(term)) then label = link:gsub(term, '') end
end
-- Auto American English punctuation positioning as its a pain
if args[2] == '.' or lib.isNotEmpty(args['dot']) or lib.isNotEmpty(args['dotspc']) then
if label:find('"$') then
if not label:find('[%.%?!,]"$') then
label = label:gsub('"$', '."')
end
else suffix = suffix .. '.'
end
if lib.isNotEmpty(args['dotspc']) then suffix = suffix .. ' ' end
elseif args[2] == ',' or lib.isNotEmpty(args['comma']) or lib.isNotEmpty(args['commaspc']) then
if label:find('"$') then
if not label:find('[%.%?!,]"$') then
label = label:gsub('"$', ',"')
end
else suffix = suffix .. ','
end
if lib.isNotEmpty(args['commaspc']) then suffix = suffix .. ' ' end
end
if args.nolink then
return label .. suffix
else
return '[[' .. link .. '|' .. label .. ']]' .. suffix
end
end
return p