Documentation for this module may be created at Module:CiteGithub/doc
local CiteGithub = {}
local StringEx = require("Module:StringExtension")
local FILE_PATH_PREFIX = "https://github.com/teamstarcup/starcup/blob/"
function CiteGithub.main(frame)
local args = frame:getParent().args
local argPath = args[1]
if not StringEx.startswith(argPath, FILE_PATH_PREFIX) then
error("Invalid argument: string must point to a file in the starcup" ..
" github repository")
return
end
local trimmedPath = StringEx.replace(argPath, "https://github.com/teamstarcup/starcup/blob/", "")
local firstSlashIndex, _evilStealthReturnValue = trimmedPath:find("/")
local filePath = trimmedPath:sub(firstSlashIndex)
-- trim off line number range
local firstOctothorpeIndex, _evilStealthReturnValue = filePath:find("#")
local displayedFilePath = filePath:sub(1, firstOctothorpeIndex)
return string.format("[%s %s]", argPath, displayedFilePath)
end
return CiteGithub