Module:A or an: Difference between revisions

Content deleted Content added
mw.loadData
tweaks
Line 1:
local p = {}
local getArgs = require('Module:Arguments').getArgs
local words = mw.loadData('Module:A or an/words')
 
Line 20 ⟶ 19:
 
function p._main(args)
local s = args[1] and mw.text.trim(args[1])
local pron = 'a'
local ret = ''
if s and s ~= '' then
local origStr = s
s = gsub(s, '<%/?[A-Za-z]+[^>]*>', '') -- Remove HTML tags
s = gsub(s, '%[%[[^%|]+%|(.-)%]%]', '%1') -- Remove wikilinks
s = gsub(s, '<%/?[A-Za-z]+[^>]*->', '') -- Remove HTML tags
s = gsub(s, '%[%[[^%|]+%|(..-)%]%]', '%1') -- Remove wikilinks
s = gsub(gsub(s, '%[%[', ''), '%]%]', '')
s = gsub(s, '^["%$\'%(<%[%{¢-¥₠-₿]+', '') -- Strip some symbols at the beginning
Line 32 ⟶ 33:
if find(s, '^[0-9]') then -- It begins with a number
s = match(s, '^[0-9]*+') -- Extract the number
if findWord(s, words['vNums']) then -- '18' etc.
pron = 'an'
end
elseif match(s, '^[0-9%u]*+$') then -- It looks like an acronym
if find(s, '^[' .. ucVvChars .. ']')
and not findWord(s, words['cvAcronyms']) -- Exclude 'NASA' etc.
Line 57 ⟶ 58:
end
end
ret = pron .. ' ' .. args[1]origStr
end
Line 64 ⟶ 65:
 
function p.main(frame)
return p._main(frame:getParent().args)
local args = getArgs(frame)
return p._main(args)
end