Difference between revisions of "Module:Italic title"

From blackwiki
Jump to navigation Jump to search
blackwiki>Mr. Stradivarius
(allow the ability to specify the "noerror" parameter)
blackwiki>Mr. Stradivarius
(allow this to be called from Lua, and make it more compact)
Line 3: Line 3:
 
local p = {}
 
local p = {}
  
function p.main(frame)
+
function p._main(args, frame, title)
local args = require('Module:Arguments').getArgs(frame, {
+
args = args or {}
wrappers = 'Template:Italic title'
+
frame = frame or mw.getCurrentFrame()
})
+
title = title or mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()
 
 
 
-- Find the parts before and after the disambiguation parentheses, if any.
 
 
local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
 
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
 
local result
 
if prefix and parentheses and args.all ~= 'yes' then
 
if prefix and parentheses and args.all ~= 'yes' then
result = "''" .. prefix .. "'' " .. parentheses
+
result = string.format("''%s'' %s", prefix, parentheses)
 
else
 
else
result = "''" .. title.text .. "''"
+
result = string.format("''%s''", title.text)
 
end
 
end
 
-- Add the namespace if we're not in mainspace.
 
 
if title.namespace ~= 0 then
 
if title.namespace ~= 0 then
result = mw.site.namespaces[title.namespace].name .. ':' .. result
+
result = title.nsText .. ':' .. result
 
end
 
end
 +
return frame:callParserFunction('DISPLAYTITLE', result, args[1])
 +
end
  
-- Call displaytitle with the text we generated.
+
function p.main(frame)
return mw.getCurrentFrame():callParserFunction(
+
local args = require('Module:Arguments').getArgs(frame, {
'DISPLAYTITLE',
+
wrappers = 'Template:Italic title'
result,
+
})
args[1]
+
return p._main(args, frame)
)
+
end
end  
 
  
 
return p
 
return p

Revision as of 23:37, 3 March 2015

This module implements {{italic title}} and {{italic dab}}. Please see the template pages for documentation.


-- This module implements {{italic title}}.

local p = {}

function p._main(args, frame, title)
	args = args or {}
	frame = frame or mw.getCurrentFrame()
	title = title or mw.title.getCurrentTitle()
	local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
	local result
	if prefix and parentheses and args.all ~= 'yes' then
		result = string.format("''%s'' %s", prefix, parentheses)
	else
		result = string.format("''%s''", title.text)
	end
	if title.namespace ~= 0 then
		result = title.nsText .. ':' .. result
	end
	return frame:callParserFunction('DISPLAYTITLE', result, args[1])
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Italic title'
	})
	return p._main(args, frame)
end

return p