Module:Print ref

local p = {};

p.ref = function (frame) local intro = frame.args.intro local work = frame.args.title local chapter_input = frame.args.chapter local issue_input = frame.args.issue local page_start = frame.args.page1 local page_end = frame.args.page2 local more = frame.args.more local booktitle = require('Module:Print ref/switcher') local titleformat, titletype = booktitle.ref(frame, reference) local work_format = '\'\ .. titleformat .. '\'\ if titletype == 'book' and page_start ~= '' then page_issue = ', p. ' .. page_start elseif titletype == 'book' and page_end ~= '' then page_issue = ', pp. ' .. page_start .. '–' .. page_end elseif titletype == 'book' and string.find(page_start, '[—-–]') then page_issue = ', pp. ' .. page_start elseif titletype == 'comic' and issue_input ~= '' then page_issue = ', Issue #' .. issue_input .. '' elseif titletype == 'comic' and issue_input ==  and chapter_input ==  then page_issue = '' else page_issue = '' end

if titletype == 'book' and chapter_input:match('%d') then chapter = ', Chapter ' .. chapter_input elseif titletype == 'book' and chapter_input ~= '' then chapter = ', "' .. chapter_input .. '"' else chapter = '' end return intro .. ' ' .. work_format .. chapter .. page_issue .. '. ' .. more end

p.anchor = function(frame) local intro = frame.args.intro local work = frame.args[1] or frame.args.title local chapter = frame.args.chapter local issue = frame.args.issue local page = frame.args.page1 local page_end = frame.args.page2 local more = frame.args.more local anchor local booktitle = require('Module:Print ref/switcher') local titleformat, titletype = booktitle.ref(frame, reference) if page == nil then page = '' end if page_end == nil then page_end = '' end

if titletype == 'book' then anchor = titleformat .. chapter .. page .. page_end .. intro .. more elseif titletype == 'gn' then anchor = titleformat .. intro .. more elseif titletype == 'comic' then anchor = titleformat .. issue .. intro .. more end return anchor end

return p