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 = string.gsub(frame.args.page1, '[^%w]+', '\–') 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) if titleformat == 'Title Missing' then work_format = 'Title missing or incorrectly entered ' elseif titletype == 'custom' then work_format = '\'\'' .. titleformat .. '\'\    else work_format = '\'\ .. titleformat .. '\'\'' end if titletype == 'book' and page_end ~= '' then page_issue = ', pp. ' .. page_start .. '\–' .. page_end elseif titletype == 'book' and string.find(page_start, '[^0-9]') then page_issue = ', pp. ' .. page_start elseif titletype == 'book' and page_start ~= '' then page_issue = ', p. ' .. 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 = string.gsub(titleformat .. chapter .. page .. page_end .. intro .. more, '[^%w]', '') elseif titletype == 'gn' then anchor = string.gsub(titleformat .. intro .. more, '[^%w]', '') elseif titletype == 'comic' then anchor = string.gsub(titleformat .. issue .. intro .. more, '[^%w]', '') end return anchor end

return p