Difference between revisions of "Module:Respell"

From Eat Every Plant
Jump to navigation Jump to search
m (1 revision: All angiosperm orders - part 5)
 
m (1 revision: From PNW foraging book - part 3)
 
(3 intermediate revisions by one other user not shown)
Line 14: Line 14:
 
v = mw.ustring.gsub(v, '_', ' ')
 
v = mw.ustring.gsub(v, '_', ' ')
 
else
 
else
if v == mw.ustring.upper(v) then
+
if mw.ustring.find(v, '%u') and v == mw.ustring.upper(v) then
v = string.format("'''%s'''", v)
+
local span = mw.html.create('span')
 +
:css('font-size', '90%')
 +
:wikitext(v)
 +
v = tostring(span)
 
end
 
end
if i ~= 1 and not hasUnsc[i - 1] then
+
if i ~= 1 and not hasUnsc[i - 1] and v ~= '-' then
 
table.insert(ret, '-')
 
table.insert(ret, '-')
 
end
 
end
Line 26: Line 29:
 
end
 
end
 
 
-- Create <small title="..."><i>...</i></small>
+
-- Create <i title="...">...</i>
local small = mw.html.create('small')
+
local italic = mw.html.create('i')
small
 
 
:attr('title', 'English pronunciation respelling')
 
:attr('title', 'English pronunciation respelling')
:tag('i')
 
 
:wikitext(table.concat(ret))
 
:wikitext(table.concat(ret))
ret = tostring(small)
+
ret = tostring(italic)
 
 
 
-- For documentation: Disable linking by adding a blank parameter at the end
 
-- For documentation: Disable linking by adding a blank parameter at the end

Latest revision as of 22:10, 13 August 2018

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 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 table.insert(ret, v) end j = i end

-- Create ... 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('%s', ret) end

return ret end

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

return p