Module:Print ref/sandbox

local p = {};

p.ref = function (frame) local intro = frame.args.intro or '' local work = frame.args.title or nil local chapterInput = frame.args.chapter or nil local issueInput = frame.args.issue or nil local pageStart = string.gsub(frame.args.page1, '[^%w]+', '\–') or nil local pageEnd = frame.args.page2 or nil local more = frame.args.more or '' local cite = frame.args.cite or nil local pageIssue -- handle blank entry if isempty(work) then return 'Title missing or incorrectly entered .' end -- issue is calculated with work name if not isempty(issueInput) then work = work .. issueInput end local printMatcher = require('Module:Print ref/Matcher') local printCode, issueNumber = printMatcher.matchCode(work) local printInfo = require('Module:Print ref/Info') local workType = printInfo.workType(printCode) local display = printInfo.display(printCode, issueNumber)

if display == 'Unknown printed work' then workFormat = "''" .. work .. "''"   elseif display == 'Invalid issue' then workFormat = 'Invalid issue ' else workFormat = display end if not isempty(pageEnd) then pageIssue = ', pp. ' .. pageStart .. '\–' .. pageEnd elseif pageStart:match('%d') then pageIssue = ', pp. ' .. pageStart elseif not isempty(pageStart) then pageIssue = ', p. ' .. pageStart elseif workType == 'comic' and isempty(issueNumber) then pageIssue = '' elseif workType == 'gn' and isempty(pageStart) then pageIssue = '' else pageIssue = '' end

if workType == 'book' and chapterInput:match('%d') then chapter = ', Chapter ' .. chapterInput elseif workType == 'book' and not isempty(chapterInput) then chapter = ', "' .. chapterInput .. '"' else chapter = '' end

if isempty(cite) then cite_needed = '' else cite_needed = '\{\{cite\}\}' end return intro .. ' ' .. workFormat .. chapter .. pageIssue .. '.' .. cite_needed .. ' ' .. more end

p.anchor = function(frame) local intro = frame.args.intro local work = frame.args[1] or frame.args.title local custom = frame.args.custom local chapter = frame.args.chapter local issue = frame.args.issue local page = frame.args.page1 or '' local pageEnd = frame.args.page2 or '' local more = frame.args.more local anchor local printInfo = require('Module:Print ref/Info') local workType = printInfo.workType(work) local title = printInfo.title(work) local display = printInfo.display(work) local issueNumber = printInfo.issueNum(work) if issueNumber == nil then issueNumber = '' end

if workType == 'book' or workType == 'dnd' or custom then anchor = string.gsub(display .. chapter .. page .. pageEnd .. intro .. more, '[^%w]', '') elseif workType == 'gn' then anchor = string.gsub(display .. intro .. more, '[^%w]', '') elseif workType == 'comic' then anchor = string.gsub(display .. issueNumber .. intro .. more, '[^%w]', '') end return anchor end

--function to determine if a string is empty function isempty(s) return s == nil or s == '' end

return p