Citation template for books.
- Module: Module:Cite book
TemplateData
Generic citation template for books and published volumes.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Author(s) | author | Author(s) of the book. Multiple authors can be separated with semicolons or 'and'. | String | suggested |
| Chapter title | chapter | Title of the chapter | String | suggested |
| Book title | title | Title of the book | String | suggested |
| Publisher | publisher | Publisher of the book | String | suggested |
| Publication date | date | Publication year or full date | Date | suggested |
| Pages | pages | Page range of the article | String | suggested |
| Page | page | Single page reference (used if pages is not set) | String | optional |
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local mArguments -- initialized lazily
local p = {}
--- Formats citation
--- @param args table - arguments
--- @return string
function p._cite(args)
checkType('_cite', 1, args, 'table')
local parts = {}
-- 1. Author
if args.author and args.author ~= "" then
table.insert(parts, args.author .. ",")
end
-- 2. Chapter
if args.chapter and args.chapter ~= "" then
table.insert(parts, '“' .. args.chapter .. ',” in')
end
-- 3. Title
if args.title and args.title ~= "" then
table.insert(parts, "''" .. args.title .. "''")
end
-- 4. Publisher and/or Date
if (args.publisher and args.publisher ~= "") or (args.date and args.date ~= "") then
local pubParts = {}
if args.publisher and args.publisher ~= "" then table.insert(pubParts, args.publisher) end
if args.date and args.date ~= "" then table.insert(pubParts, args.date) end
if #parts > 0 then
parts[#parts] = parts[#parts] .. " (" .. table.concat(pubParts, ", ") .. ")"
else
table.insert(parts, "(" .. table.concat(pubParts, ", ") .. ")")
end
end
-- 5. Page / Pages
if args.pages and args.pages ~= "" then
if #parts > 0 then
parts[#parts] = parts[#parts] .. ", pp. " .. args.pages
else
table.insert(parts, "pp. " .. args.pages)
end
elseif args.page and args.page ~= "" then
if #parts > 0 then
parts[#parts] = parts[#parts] .. ", p. " .. args.page
else
table.insert(parts, "p. " .. args.page)
end
end
local result = table.concat(parts, " ")
return (string.gsub(result, "%s+$", ""))
end
function p.cite(frame)
mArguments = require('Module:Arguments')
return p._cite(mArguments.getArgs(frame))
end
return p