Module:Respell: Difference between revisions
Appearance
Content deleted Content added
abandon small/bold, instead lower stressed syllables per discussion at Template talk:Respell |
refine |
||
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 = {} |
||
local |
local link |
||
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 |
if v ~= '' and v ~= "'" then |
||
if ret[#ret] and not (ret[#ret]:find('_') or ret[#ret]:find('%-$')) |
|||
and not (v:find('_') or v:find('^%-')) |
|||
⚫ | |||
⚫ | |||
v = mw.ustring.gsub(v, '_', ' ') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if mw.ustring.find(v, '%u') and v == mw.ustring.upper(v) then |
|||
⚫ | |||
local span = mw.html.create('span') |
|||
v = '<span style="font-size:90%">' .. v .. '</span>' |
|||
:wikitext(v) |
|||
v = tostring(span) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
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 |
|||
⚫ | |||
end |
|||
-- Create <i title="...">...</i> |
|||
local italic = mw.html.create('i') |
|||
⚫ | |||
:wikitext(table.concat(ret)) |
|||
ret = tostring(italic) |
|||
-- For documentation: Disable linking by adding a blank parameter at the end |
|||
if args[j] ~= '' then |
|||
⚫ | |||
end |
end |
||
⚫ | |||
table.concat(ret):gsub('_', ' ') .. '</i>' |
|||
⚫ | |||
return ret |
return ret |
||
end |
end |
||
function p.main(frame) |
function p.main(frame) |
||
⚫ | |||
local args = getArgs(frame, {removeBlanks = false}) |
|||
⚫ | |||
end |
end |
||
Revision as of 23:58, 17 January 2019
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 21,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 = {}
function p._main(args)
local ret = {}
local 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