Documentation for this module may be created at Module:Sandbox/Gonnym/Fictional element short description/doc

-- Fictional <fiction type> - "Fictional character"
-- Fictional <fiction type> in a <media type> - "Fictional character in a television series"
-- Fictional <fiction type> in the <media type> ''<series>'' - "Fictional character in the television series ''Lost''"
-- Fictional <fiction type> in ''<series>'' - "Fictional character in ''Lost''"
-- Fictional <fiction type> in the <franchise> franchise - "Fictional character in the Arrowverse franchise"

-- This module requires the use of the following modules:
local getArgs = require('Module:Arguments').getArgs
local isInfoboxInLead = require('Module:Is infobox in lead')._main

-- Local function which is used to clean the values from unwanted characters.
local function cleanValues(args)
	for _, v in ipairs({'episode_num', 'season_num', 'season_num_uk', 'series_name'}) do
		if args[v] then
			args[v] = args[v]:gsub('\127[^\127]*UNIQ%-%-(%a+)%-%x+%-QINU[^\127]*\127', '')					-- Remove all strip-markers.
			args[v] = args[v]:gsub('</? *br */?>', ' ')														-- Replace <br /> (and variants) with space character.
			args[v] = args[v]:gsub('%b<>[^<]+%b<>', '')														-- Remove html markup.
			args[v] = args[v]:gsub('%b<>', '')																-- Remove self-closed html tags.
			args[v] = args[v]:gsub('%[%[[^|]+|([^%]]+)%]%]', '%1')											-- Remove wiki-link retain label.
			args[v] = args[v]:gsub('%[%[([^%]]+)%]%]', '%1')												-- Remove wiki-link retain article.
			args[v] = args[v]:gsub('%[%S+ +([^%]]-)%]', '%1')												-- Remove URLs retain label.
			args[v] = args[v]:gsub('%[[^%]]-%]', '')														-- Remove all remaining URLs.

			if (args[v] == '') then																			-- Check if the value is an empty string.
				args[v] = nil																				-- The value is an empty string; Set it to nil.
			end
		end
	end
	return args																								-- Return args.
end

-- Local function which does the actual main process.
local function _getShortDescription(frame, args, fictionype)
	args = cleanValues(args)																				-- Call cleanValues() to remove all unwanted characters.

	local series = args['series']
	local franchise = args['franchise']
	

	local test = args['test']																				-- This param should only be used by tests runned through /testcases.
	local doc = args['doc']																					-- This param should only be used by the documentation page.

	local shortDescription, trackingCat = createDescription(
		episodeNumberText, seasonNumber, seasonNumberUK, tvSeriesName, isDoubleEpisode, notDisambiguated)	-- Call createDescription() and return two values: the episode's short description and tracking category.

	if (test == nil and doc == nil) then																	-- Check if the invoking page is from /testcases or doc pages.
		local tableData = {shortDescription, 'noreplace'}													-- Invoking page isn't a test; Create a table for the short description parameter.
		return frame:expandTemplate({title = 'short description', args = tableData}) .. trackingCat			-- Return expanded short description with tracking category.
	else
		return shortDescription																				-- Invoking page is a test; Return only short description.
	end
end

--[[
Wrapper function which handles the processing of the arguments 
from multiple public invoked functions.

Parameters:
	-- |TODO=				— required; TODO.
--]]
local function makeInvokeFunc(funcName)
	return function (frame)
		local args = getArgs(frame)

		if (isInfoboxInLead(args["template_name"]) ~= "true") then
			return nil
		end
		
		return p[funcName](frame, args)
	end
end

p.getCharacterShortDescription = makeInvokeFunc('_getCharacterShortDescription')

--[[
Public function which is used TODO

Parameters: See makeInvokeFunc() for documentation.
--]]
function p._getCharacterShortDescription(frame, args)
	return getShortDescription(frame, args, "character")
end

p.getRaceShortDescription = makeInvokeFunc('_getRaceShortDescription')

--[[
Public function which is used to TODO

Parameters: See makeInvokeFunc() for documentation.
--]]
function p._getRaceShortDescription(frame, args)
	return getShortDescription(frame, args, "race")
end

return p