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 33: | Line 33: | ||
local args = require('Module:Arguments').getArgs(frame) |
local args = require('Module:Arguments').getArgs(frame) |
||
-- input validation |
-- input validation |
||
if not args['specifier |
if not args['specifier'] then error('"specifier" argument is required') end |
||
if args['scope'] then args['specifier'] = args['scope'] end |
|||
local title = mw.title.getCurrentTitle().prefixedText |
local title = mw.title.getCurrentTitle().prefixedText |
||
Revision as of 17:45, February 20, 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(specifier, title)
-- input validation
checkTypeForNamedArg('getDisplayTitle', 'specifier', specifier, 'string', false)
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string', false)
if title:find(' %(' .. specifier .. '%)$') then
local result, _ = title:gsub(' %(' .. specifier .. '%)', '')
return result
end
if title:find(' %(' .. specifier .. ', ') then
local result, _ = title:gsub(' %(' .. specifier .. ', ', ' (')
return result
end
return title
end
function p.invoke(frame)
local args = require('Module:Arguments').getArgs(frame)
-- input validation
if not args['specifier'] then error('"specifier" argument is required') end
return getDisplayTitle(args['specifier'], mw.title.getCurrentTitle().text)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
-- input validation
if not args['specifier'] then error('"specifier" argument is required') end
local title = mw.title.getCurrentTitle().prefixedText
local displayTitle = getDisplayTitle(args['specifier'], title)
if title ~= displayTitle then
return mw.ext.displaytitle.set(displayTitle)
else
return ''
end
end
return p