Jump to content

Module:Respell/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nardog (talk | contribs) at 19:23, 22 June 2017 (simplify). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}
local getArgs = require('Module:Arguments').getArgs

function p._main(args)
	local ret = {}
	local hasUnsc = {}
	local j = 0
	
	for i, v in ipairs(args) do
		-- Compatibility: Ignore arguments that only contain an apostrophe
		if v and v ~= '' and v ~= '\'' then
			hasUnsc[i] = mw.ustring.find(v, '_')
			if hasUnsc[i] then
				v = mw.ustring.gsub(v, '_', ' ')
			else
				if v == mw.ustring.upper(v) then
					v = string.format("'''%s'''", v)
				end
				if i ~= 1 and not hasUnsc[i - 1] then
					v = '-' .. v
				end
			end
			
			table.insert(ret, v)
		end
		j = i
	end
	
	ret = string.format(
		"<small title=\"English pronunciation respelling\">''%s''</small>",
		table.concat(ret)
		)
	
	-- 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
	
	return ret
end

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

return p