Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
You must create an account or log in to edit.

Module:Remove parentheses: Difference between revisions

From Amaranth Legacy, available at amaranth-legacy.community
Content deleted Content added
No edit summary
No edit summary
Line 1: Line 1:
local libraryUtil = require('libraryUtil')
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg


local p = {}
local p = {}
Line 6: Line 6:
local function getDisplayTitle(scope, title)
local function getDisplayTitle(scope, title)
-- input validation
-- input validation
checkType('getDisplayTitle', 1, scope, 'string')
checkTypeForNamedArg('getDisplayTitle', 'scope', scope, 'string')
checkType('getDisplayTitle', 2, title, 'string')
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string')


if title:find(' (' .. scope .. ')') then
if title:find(' (' .. scope .. ')') then
displaytitle, _ = title:gsub('_%(' .. scope .. '%)', '')
local displaytitle, _ = title:gsub('_%(' .. scope .. '%)', '')
return displaytitle
return displaytitle
end
elseif title:find(' (' .. scope .. ',') then

displaytitle, _ = title:gsub('_%(' .. scope .. ',', ' (')
if title:find(' (' .. scope .. ',') then
local displaytitle, _ = title:gsub('_%(' .. scope .. ',', ' (')
return displaytitle
return displaytitle
else
return title
end
end

return title
end
end



Revision as of 18:01, 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')
	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