More actions
create lua module- I haven't tested this at all so don't use it on the template yet |
getparent |
||
Line 2: | Line 2: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | local args = frame:getParent().args | ||
local result = '' | local result = '' | ||
if not args.book then | if not args.book then |
Revision as of 20:58, 12 January 2025
Documentation for this module may be created at Module:Cite book/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local result = ''
if not args.book then
return '{{error|<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 formatChapter(chapter)
if tonumber(chapter, 10) then
return 'chapter ' .. chapter
else
return chapter
end
end
function formatBookTitle(title)
local page = mw.title.new(title, 0)
if page and page.exists then
return '\'\'[[' .. title .. ']]\'\''
else
return '\'\'' .. title .. '\'\''
end
end
return p