More actions
getparent |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local error = require('Module:error') | |||
function p.main(frame) | function p.main(frame) | ||
Line 5: | Line 7: | ||
local result = '' | local result = '' | ||
if not args.book then | if not args.book then | ||
return ' | return error.error({ | ||
message = '<code>book</code> parameter is required' | |||
}) | |||
else | else | ||
result = formatBookTitle(args.book) | result = formatBookTitle(args.book) | ||
Line 24: | Line 28: | ||
end | end | ||
function formatChapter(chapter) | function p.formatChapter(chapter) | ||
if tonumber(chapter, 10) then | if tonumber(chapter, 10) then | ||
return 'chapter ' .. chapter | return 'chapter ' .. chapter | ||
Line 32: | Line 36: | ||
end | end | ||
function formatBookTitle(title) | function p.formatBookTitle(title) | ||
local page = mw.title.new(title, 0) | local page = mw.title.new(title, 0) | ||
if page and page.exists then | if page and page.exists then |
Revision as of 06:44, 16 January 2025
Documentation for this module may be created at Module:Cite book/doc
local p = {}
local error = require('Module:error')
function p.main(frame)
local args = frame:getParent().args
local result = ''
if not args.book then
return error.error({
message = '<code>book</code> parameter is required'
})
else
result = formatBookTitle(args.book)
end
if args.chapter then
if tonumber(chapter, 10) then
result = result .. ', chapter ' .. args.chapter
else
result = result .. ', ' .. args.chapter
end
end
if args.page then
result = result .. ', page ' .. args.page
elseif args.paragraph then
result = result .. ', paragraph ' .. args.paragraph
end
return result
end
function p.formatChapter(chapter)
if tonumber(chapter, 10) then
return 'chapter ' .. chapter
else
return chapter
end
end
function p.formatBookTitle(title)
local page = mw.title.new(title, 0)
if page and page.exists then
return '\'\'[[' .. title .. ']]\'\''
else
return '\'\'' .. title .. '\'\''
end
end
return p