Jump to content

Module:Respell/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 7: Line 7:
-- Compatibility: Ignore arguments that only contain an apostrophe
-- Compatibility: Ignore arguments that only contain an apostrophe
if v ~= '' and v ~= "'" then
if v ~= '' and v ~= "'" then
if ret[#ret] and not ret[#ret]:find('[%-_]$') and not v:find('_') then
if ret[#ret] and not (ret[#ret]:find('_') or ret[#ret]:find('%-$'))
and not (v:find('_') or v:find('^%-'))
then
table.insert(ret, '-')
table.insert(ret, '-')
end
end
Line 19: Line 21:
end
end
ret = '<i title="English pronunciation respelling">' ..
ret = '<i title="English pronunciation respelling">' ..
string.gsub(table.concat(ret), '_', ' ') .. '</i>'
table.concat(ret):gsub('_', ' ') .. '</i>'
ret = link and '[[Help:Pronunciation respelling key|' .. ret .. ']]' or ret
ret = link and '[[Help:Pronunciation respelling key|' .. ret .. ']]' or ret
return ret
return ret

Revision as of 23:48, 17 January 2019

local p = {}

function p._main(args)
	local ret, link = {}
	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
		-- For documentation: Blank parameter at the end suppresses the link
		if not args[i + 1] and v ~= '' then link = true end
	end
	ret = '<i title="English pronunciation respelling">' ..
		table.concat(ret):gsub('_', ' ') .. '</i>'
	ret = link and '[[Help:Pronunciation respelling key|' .. ret .. ']]' or ret
	return ret
end

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

return p