Module:BookSwitch

-- local p = {}

local bookData = mw.loadData('Module:BookSwitch/data') function p.bookFormat(frame) local tArgs = frame.args

-- get the arguments from parent of frame object -- if the module was invoked through an intermediate template if frame:getParent and frame:getParent.args[1] then tArgs = frame:getParent.args end

local book = tArgs[1] or "" local bold = (tArgs[2] and tArgs[2] ~= "")

-- Split the book name at ":" or "-" into Show and Subtitle local fakeShow, subtitle = mw.ustring.match(book,                   "^%s*([^%:%-]-)%s*[%:%-]%s*(.-)%s*$")

-- If ':' or '-' not in book name -- then subtitle is whole book name if not subtitle then -- trim leading and trailing whitespace subtitle = mw.ustring.gsub(book, "^%s*(.-)%s*$", "%1") end

-- default values local show = "Arrowverse Wiki" local year = "Arrowverse Wiki" local mid = ": "

if bookData[subtitle] then show = bookData[subtitle][1] year = bookData[subtitle][2] -- use separator if defined in bookData -- or use default value mid = bookData[subtitle][3] or ": " end

local fulltitle = show .. mid .. subtitle

-- if Show Name is included in Book Name but -- is not equal to show name from bookData if fakeShow and fakeShow ~= show then year = "Arrowverse Wiki" end

-- This is not needed?? -- it is also handled in ColorSwitch if show == "S.T.A.R. Labs" or show == "The Flash" then show="The Flash (The CW)" end

local hoverInfo = ""

if year == "Arrowverse Wiki" then hoverInfo = "'            .. subtitle .. " " .. ""   elseif bold then hoverInfo = "'            .. subtitle .. " " else hoverInfo = "'            .. fulltitle .. " " end return hoverInfo end return p --