Module:Soldier: Difference between revisions
Spell out Army branch abbreviations in the infobox. |
Categorize soldiers from MII codes in notes. |
||
| Line 917: | Line 917: | ||
end | end | ||
return lead | return lead | ||
end | |||
local function researchNotesSection(content) | |||
if not content or content == '' then | |||
return '' | |||
end | |||
local startPos = mw.ustring.find(content, '== Research notes ==', 1, true) | |||
if not startPos then | |||
return '' | |||
end | |||
local after = mw.ustring.sub(content, startPos + 20) | |||
local nextHead = mw.ustring.find(after, '\n== ', 1, true) | |||
if nextHead then | |||
return mw.ustring.sub(after, 1, nextHead - 1) | |||
end | |||
return after | |||
end | |||
local function noteTeamNames(text) | |||
text = mw.ustring.upper(tostring(text or '')) | |||
local seen = {} | |||
local names = {} | |||
local function add(name) | |||
if name ~= '' and not seen[name] then | |||
seen[name] = true | |||
table.insert(names, name) | |||
end | |||
end | |||
local work = text | |||
for num, letter in string.gmatch(work, 'MII%s+(%d+)%s*%-%s*([A-Z])') do | |||
add('MII ' .. num .. '-' .. letter) | |||
end | |||
work = string.gsub(work, 'MII%s+%d+%s*%-%s*[A-Z]', ' ') | |||
for num in string.gmatch(work, 'MII%s+(%d+)') do | |||
add('MII ' .. num) | |||
end | |||
for num, letter in string.gmatch(' ' .. text, '[^%d]([45]%d%d)%s*%-%s*([GI])') do | |||
add('MII ' .. num .. '-' .. letter) | |||
end | |||
for num in string.gmatch(text, 'IPW%s+(%d+)') do | |||
add('IPW ' .. num) | |||
end | |||
return names | |||
end | |||
function p.noteTeamCategories(frame) | |||
local title = mw.title.getCurrentTitle() | |||
if not title or not title.getContent then | |||
return '' | |||
end | |||
local ok, content = pcall(function() | |||
return title:getContent() | |||
end) | |||
if not ok or not content then | |||
return '' | |||
end | |||
local bits = {} | |||
for _, name in ipairs(noteTeamNames(researchNotesSection(content))) do | |||
table.insert(bits, '[[Category:Team ' .. name .. ']]') | |||
end | |||
return table.concat(bits) | |||
end | end | ||
| Line 930: | Line 991: | ||
return '' | return '' | ||
end | end | ||
local | local section = researchNotesSection(content) | ||
if | if section == '' then | ||
return '' | return '' | ||
end | end | ||
local items = {} | local items = {} | ||