Module:Remove parentheses
From Amaranth Legacy, available at amaranth-legacy.community
More actions
Removes parentheses in a page title; used by Template:Remove parentheses
local libraryUtil = require('libraryUtil')
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg
local p = {}
local function getDisplayTitle(scope, title)
-- input validation
checkTypeForNamedArg('getDisplayTitle', 'scope', scope, 'string')
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string')
if title:find('_(' .. scope .. ')') then
local displaytitle, _ = title:gsub('_%(' .. scope .. '%)', '')
return displaytitle
end
if title:find('_(' .. scope .. ',') then
local displaytitle, _ = title:gsub('_%(' .. scope .. ',', ' (')
return displaytitle
end
return title
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
-- input validation
if not args['scope'] then error('"scope" argument is required') end
return frame:callParserFunction(
'DISPLAYTITLE',
getDisplayTitle(args['scope'], mw.title.getCurrentTitle().prefixedText)
)
end
return p