Module:Print ref/sandbox

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 cite = frame.args.cite 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 .. '\'\'' 	elseif titletype == 'dnd' then work_format = '\'\'' .. titleformat .. '\'\    else work_format = '\'\ .. titleformat .. '\'\'' end if titletype == 'comic' and issue_input ~= '' then page_issue = ', Issue #' .. issue_input .. '' elseif page_end ~= '' then page_issue = ', pp. ' .. page_start .. '\–' .. page_end elseif string.find(page_start, '[^0-9]') then page_issue = ', pp. ' .. page_start elseif page_start ~= '' then page_issue = ', p. ' .. page_start elseif titletype == 'comic' and issue_input == '' then page_issue = '' elseif titletype == 'gn' and page_start == '' 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

if cite == '' or cite == nil then cite_needed = '' else cite_needed = '\{\{cite\}\}' end return intro .. ' ' .. work_format .. chapter .. page_issue .. '.' .. cite_needed .. ' ' .. 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' or titletype == 'dnd' or titletype == 'custom' 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