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 1: Line 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


function p._main(args)
function p._main(args)
local ret = {}
local ret, link = {}
local hasUnsc = {}
local j = 0
for i, v in ipairs(args) do
for i, v in ipairs(args) do
v = mw.text.trim(v)
-- Compatibility: Ignore arguments that only contain an apostrophe
-- Compatibility: Ignore arguments that only contain an apostrophe
if v and v ~= '' and v ~= "'" then
if v ~= '' and v ~= "'" then
hasUnsc[i] = mw.ustring.find(v, '_')
if ret[#ret] and not ret[#ret]:find('[%-_]$') and not v:find('_') then
table.insert(ret, '-')
if hasUnsc[i] then
end
v = mw.ustring.gsub(v, '_', ' ')
if v:find('^%u+$') then
else
v = '<span style="font-size:90%">' .. v .. '</span>'
if mw.ustring.find(v, '%u') and v == mw.ustring.upper(v) then
local span = mw.html.create('span')
:css('font-size', '90%')
:wikitext(v)
v = tostring(span)
end
if i ~= 1 and not hasUnsc[i - 1] and v ~= '-' then
table.insert(ret, '-')
end
end
end
table.insert(ret, v)
table.insert(ret, v)
end
end
-- For documentation: Blank parameter at the end suppresses the link
j = i
if not args[i + 1] and v ~= '' then link = true end
end
-- Create <i title="...">...</i>
local italic = mw.html.create('i')
:attr('title', 'English pronunciation respelling')
:wikitext(table.concat(ret))
ret = tostring(italic)
-- For documentation: Disable linking by adding a blank parameter at the end
if args[j] ~= '' then
ret = string.format('[[Help:Pronunciation respelling key|%s]]', ret)
end
end
ret = '<i title="English pronunciation respelling">' ..
string.gsub(table.concat(ret), '_', ' ') .. '</i>'
ret = link and '[[Help:Pronunciation respelling key|' .. ret .. ']]' or ret
return ret
return ret
end
end


function p.main(frame)
function p.main(frame)
return p._main(frame:getParent().args)
local args = getArgs(frame, {removeBlanks = false})
return p._main(args)
end
end



Revision as of 23:27, 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('[%-_]$') and not 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">' ..
		string.gsub(table.concat(ret), '_', ' ') .. '</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