Module:CharList: Difference between revisions
From Elwiki
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
local named_list = {} | local named_list = {} | ||
local not_exist = {} | |||
local chars = frame:preprocess('{{:MediaWiki:NavSidebar/Character}}') | local chars = frame:preprocess('{{:MediaWiki:NavSidebar/Character}}') | ||
-- Get rid of link wikitext. | -- Get rid of link wikitext. | ||
Line 41: | Line 42: | ||
-- Remove link placeholders. | -- Remove link placeholders. | ||
for k2, v2 in ipairs(named_list[k][i]) do | for k2, v2 in ipairs(named_list[k][i]) do | ||
named_list[k][i][k2] = | local name = named_list[k][i][k2]:gsub('</div>', ''):gsub("<div id='nav'>", '') | ||
named_list[k][i][k2] = trim(name:gsub('%#!%|', '')); | |||
-- Create a table of characters with placeholders, marked as not released. | |||
if string.find(name, '%#!%|') then | |||
table.insert(not_exist, name) | |||
end | |||
end | end | ||
Line 54: | Line 61: | ||
-- Output point | -- Output point | ||
local char_list = { | local char_list = { | ||
base_order, named_list | base_order, named_list, not_exist | ||
} | } | ||
Revision as of 18:12, 20 October 2022
Documentation for this module may be created at Module:CharList/doc
require('Module:CommonFunctions');
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame)
local args = getArgs(frame)
local named_list = {}
local not_exist = {}
local chars = frame:preprocess('{{:MediaWiki:NavSidebar/Character}}')
-- Get rid of link wikitext.
:gsub('%[%[', ''):gsub('%]%]', '')
-- Replace star separators to distinct strings to make it easier.
:gsub('%*%*%*', 'SEP1'):gsub('%*%*', 'SEP2'):gsub('%*', 'SEP3')
local base_order = {}
-- Compose a table out of the string.
chars = split(chars, 'SEP3', true)
table.remove(chars, 1)
for k,v in ipairs(chars) do
chars[k] = split(v, 'SEP2', true)
for k2, v2 in ipairs(chars[k]) do
chars[k][k2] = split(v2, 'SEP1', true);
if #chars[k][k2] == 1 then
local base = chars[k][k2][1]
-- Sort by base names.
if not string.find(base, '%#!') then
chars[k][1] = nil
named_list[base] = chars[k]
-- Save the order of iteration, because Lua doesn't remember it.
table.insert(base_order, trim(base));
end
end
end
end
-- Shift the new table's indexes up after getting rid of the base name.
for k, v in pairs(named_list) do
local i = 2
while (i <= #named_list[k]) do
-- Remove link placeholders.
for k2, v2 in ipairs(named_list[k][i]) do
local name = named_list[k][i][k2]:gsub('</div>', ''):gsub("<div id='nav'>", '')
named_list[k][i][k2] = trim(name:gsub('%#!%|', ''));
-- Create a table of characters with placeholders, marked as not released.
if string.find(name, '%#!%|') then
table.insert(not_exist, name)
end
end
-- Shifting.
named_list[k][i-1] = named_list[k][i]
i = i + 1
end
named_list[k][#named_list[k]] = nil
-- Remove link placeholders.
end
-- Output point
local char_list = {
base_order, named_list, not_exist
}
return char_list
end
return p