Documentation for this module may be created at Module:CharacterAlphabeticallyThreePerRow/doc

local p = {}

-- p.main returns a table where girls are grouped alphabetically in rows of three.
-- The rows of the table are separated by ';', while cells by ','
-- e.g.: Akemi Homura,Akino Kaede,Amane Tsukasa;Amane Tsukuyo,Awane Kokoro,Ayano Rika; (...)
function p.main(frame)
  local character_list_page = frame.args['CharacterListSource']
  return p.render(frame, character_list_page)
end

  
function p.render(frame, character_list_page)
  local chars = {}
  
  local list_str = frame:expandTemplate{ title = character_list_page }
  for girl in (list_str .. ";"):gmatch("%s*([^;]*)%s*;") do
    table.insert(chars, girl)
  end
  -- sorted name list
  table.sort(chars)
  
  -- renders in rows of 3, 
  local output = ''
  for id, name in ipairs(chars) do
    output = output .. name
    if id % 3 == 0 then
        output = output .. ";"
    else
        output = output .. ","
    end
    

  end
  return output
  -- Render output
  
end

return p
Community content is available under CC-BY-SA unless otherwise noted.