Module:Remove parentheses: Difference between revisions
From Amaranth Legacy, available at amaranth-legacy.community
More actions
Content deleted Content added
Tesinormed (talk | contribs) No edit summary |
Tesinormed (talk | contribs) No edit summary |
||
| Line 6: | Line 6: | ||
local function getDisplayTitle(scope, title) |
local function getDisplayTitle(scope, title) |
||
-- input validation |
-- input validation |
||
checkTypeForNamedArg('getDisplayTitle', 'scope', scope, 'string') |
checkTypeForNamedArg('getDisplayTitle', 'scope', scope, 'string', false) |
||
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string') |
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string', false) |
||
if title:find(' (' .. scope .. ')') then |
if title:find(' (' .. scope .. ')') then |
||
| Line 25: | Line 25: | ||
local args = require('Module:Arguments').getArgs(frame) |
local args = require('Module:Arguments').getArgs(frame) |
||
-- input validation |
-- input validation |
||
if not args['scope'] then error(' |
if not args['scope'] then error('<code>scope</code> argument is required') end |
||
return frame:callParserFunction( |
return frame:callParserFunction( |
||
Revision as of 18:02, January 28, 2025
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', false)
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string', false)
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('<code>scope</code> argument is required') end
return frame:callParserFunction(
'DISPLAYTITLE',
getDisplayTitle(args['scope'], mw.title.getCurrentTitle().prefixedText)
)
end
return p