Difference between revisions of "Module:Respell"

From blackwiki
Jump to navigation Jump to search
blackwiki>Nardog
(avoid dangling hyphens)
blackwiki>Nardog
(disabling link is now done by link=no because people were inadvertently putting blank parameters at the end)
Line 3: Line 3:
 
function p._main(args)
 
function p._main(args)
 
local ret = {}
 
local ret = {}
local link
 
 
for i, v in ipairs(args) do
 
for i, v in ipairs(args) do
 
v = mw.text.trim(v)
 
v = mw.text.trim(v)
Line 18: Line 17:
 
table.insert(ret, v)
 
table.insert(ret, v)
 
end
 
end
-- For documentation: Blank parameter at the end suppresses the link
 
if not args[i + 1] and v ~= '' then link = true end
 
 
end
 
end
 
ret = '<i title="English pronunciation respelling">' ..
 
ret = '<i title="English pronunciation respelling">' ..
 
table.concat(ret):gsub('_', ' ')
 
table.concat(ret):gsub('_', ' ')
:gsub(' %-', ' -&#8288;') -- Avoid dangling hyphens
+
-- Avoid dangling hyphens
 +
:gsub(' %-', ' -&#8288;')
 
:gsub('^%-', '-&#8288;')
 
:gsub('^%-', '-&#8288;')
 
.. '</i>'
 
.. '</i>'
ret = link and '[[Help:Pronunciation respelling key|' .. ret .. ']]' or ret
+
if args.link ~= 'no' then
 +
ret = '[[Help:Pronunciation respelling key|' .. ret .. ']]'
 +
end
 
return ret
 
return ret
 
end
 
end

Revision as of 13:30, 16 March 2019

This module implements {{Respell}}. Please see the template page for documentation.


local p = {}

function p._main(args)
	local ret = {}
	for i, v in ipairs(args) do
		v = mw.text.trim(v)
		-- Compatibility: Ignore arguments that only contain an apostrophe
		if v ~= '' and v ~= "'" then
			if ret[#ret] and not (ret[#ret]:find('_') or ret[#ret]:find('%-$'))
				and not (v:find('_') or v:find('^%-'))
			then
				table.insert(ret, '-')
			end
			if v:find('^%u+$') then
				v = '<span style="font-size:90%">' .. v .. '</span>'
			end
			table.insert(ret, v)
		end
	end
	ret = '<i title="English pronunciation respelling">' ..
		table.concat(ret):gsub('_', ' ')
			 -- Avoid dangling hyphens
			:gsub(' %-', ' -&#8288;')
			:gsub('^%-', '-&#8288;')
		.. '</i>'
	if args.link ~= 'no' then
		ret = '[[Help:Pronunciation respelling key|' .. ret .. ']]'
	end
	return ret
end

function p.main(frame)
	return p._main(frame:getParent().args)
end

return p