-- This module implements {{italic title}}, {{italic title prefixed}},
-- and {{lcfirstitalictitle}}.
local p = {}
local function _main(start)
start = start or 1
local title = mw.title.getCurrentTitle()
-- Find the parts before and after the disambiguation parentheses, if any.
local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
-- If parentheses were found, italicise only the part before them. Otherwise
-- italicise the whole title.
local result
if prefix and parentheses and args.all ~= 'yes' then
result = prefix
else
result = title.text
parentheses = nil
end
result = result:sub(1, start - 1) .. "''" .. result:sub(start) .. "''"
if parenthesis then
result = result .. " " .. parentheses
end
-- Add the namespace if we're not in mainspace.
if title.namespace ~= 0 then
result = mw.site.namespaces[title.namespace].name .. ':' .. result
end
return result
end
function p.italic_title(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Italic title'
})
-- Call displaytitle with the text we generated.
return mw.getCurrentFrame():callParserFunction(
'DISPLAYTITLE',
_main(),
args[1]
)
end
function p.lcfirstitalictitle(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Lcfirstitalictitle'
})
-- Call displaytitle with the text we generated.
local lang = mw.language.getContentLanguage()
return mw.getCurrentFrame():callParserFunction(
'DISPLAYTITLE',
lang:lcfirst(_main()),
args[1] -- TODO: what are original parameters in Template:Lcfirstitalictitle?
)
end
function p.italic_title_prefixed(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Italic title prefixed'
})
-- Call displaytitle with the text we generated.
return mw.getCurrentFrame():callParserFunction(
'DISPLAYTITLE',
_main(arg[1]),
args[2] -- TODO: what are original parameters in Template:Italic title prefixed?
)
end
return p