Module:Spores
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Spores/doc
-- provides functions to automatically retrieve the list of Spores by extracting
-- wikilinks from the English Spores overview page at [[:Spores]], as well as
-- convenience functions for formatting the list of Spores
local m = {}
function m.getEnglishSporeNames()
sporesPageTitle = mw.title.new("Spores") -- the English version of the Spores overview page
local englishSporeNames = {}
for sporeWikilink in mw.ustring.gmatch(sporesPageTitle:getContent(), "%[%[([^|%]]*Spore)%]%]") do -- the title of the target page is the ‘captured’ (Lua regex special characters “()”); because the regex contains a capture, gmatch() returns an iterator over the matches to the capture, not the full regex
table.insert(englishSporeNames, sporeWikilink)
end
return englishSporeNames
end
function m.getWikiListOfEnglishSporeNames()
local wt = ""
local englishSporeNames = m.getEnglishSporeNames()
for i, sporeName in ipairs(englishSporeNames) do
wt = wt .. "\n* " .. sporeName
end
if wt == "" then
wt = "''no Spores found''"
else
wt = wt .. "\n"
end
return wt
end
return m