Module:Respell
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This Lua module is used on approximately 22,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module implements {{Respell}}. Please see the template page for documentation.
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 mw.ustring.find(v, '%u') and v == mw.ustring.upper(v) then
v = string.format("'''%s'''", v)
end
if i ~= 1 and not hasUnsc[i - 1] and v ~= '-' then
table.insert(ret, '-')
end
end
table.insert(ret, v)
end
j = i
end
-- Create <small title="..."><i>...</i></small>
local small = mw.html.create('small')
small
:attr('title', 'English pronunciation respelling')
:tag('i')
:wikitext(table.concat(ret))
ret = tostring(small)
-- 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