Module:Chapterlist

local p = {}

--   For use on books that use "Chapter -- function p.num(frame) return chapters(frame, "Chapter ") end

--   Same as p.num, except the format is "Part -- function p.part(frame) return chapters(frame, "Part ") end

--   Same as p.num, except it uses chapter numbers only, without "Chapter " at the beginning -- function p.numOnly(frame) return chapters(frame, "") end --   For use on books that do not follow the standard numbered chapter format, and instead use a unique name for each chapter.    * The first parameter is the title of the book's page.    * All the following parameters are the chapter titles. There can be an unlimited number of these added. -- function p.name(frame) local args = frame.args local result = "" for i, val in ipairs(args) do       if i > 1 then local link = "" .. val .. "" if i > 2 then result = result .. " • "           end result = result .. link end end return result end

function chapters(frame, chaptertype) local args = frame.args local result = "" local i = 1 local includesPrologue = "false" local link = "" if args[3] ~= nil then includesPrologue = string.lower(args[3]) end if includesPrologue == "true" then result = "Prologue" end while i <= tonumber(args[2]) do       link = "" .. chaptertype .. i .. "" if i > 1 or includesPrologue == "true" then result = result .. " • "       end result = result .. link i = i + 1 end if args[4] ~= nil then link = "" .. args[4] .. "" result = result .. " • " .. link end return result end return p