Module:Format title
Appearance
§
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
Usage
[edit]Links and formats article titles in body text for use on disambiguation or other pages. Used by templates {{fti}}, {{ftq}}, and {{ftqi}}.
- Function p._italic italicizes the non-parenthetical portion (or, optionally, only the parenthetical portion) of its argument (typically a page name).
- Function p._quotes encloses the non-parenthetical portion (or, optionally, only the parenthetical portion) of its argument (typically a page name) in quotation marks.
{{#invoke:Format title|function_name|article_title}}
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p.italic = makeInvokeFunc('_italic')
function p._italic(args)
local title = args[1]
local invert = args[2]
local prefix, parenthetical = mw.ustring.match(title, '^(.+) %(([^%(%)]+)%)$')
local result
if prefix and parenthetical and args.all ~= 'yes' then
if invert == 'i' or invert == 'inv' or invert == 'invert' then
result = string.format("%s \(\'\'%s\'\'\)", prefix, parenthetical)
else
result = string.format("\'\'%s\'\' \(%s\)", prefix, parenthetical)
end
else
result = string.format("\'\'%s\'\'", title)
end
return result
end
p.quotes = makeInvokeFunc('_quotes')
function p._quotes(args)
local title = args[1]
local invert = args[2]
local prefix, parenthetical = mw.ustring.match(title, '^(.+) %(([^%(%)]+)%)$')
local result
if prefix and parenthetical and args.all ~= 'yes' then
if invert == 'i' or invert == 'inv' or invert == 'invert' then
result = string.format("%s \(\"%s\"\)", prefix, parenthetical)
else
result = string.format("\"%s\" \(%s\)", prefix, parenthetical)
end
else
result = string.format("\"%s\"", title)
end
return result
end
return p