Module:bibliography/utils


local export = {}

-- checks whether an ID is an abbreviation or not
function export.is_abbrev(sid)
	return not sid:match(":%d+[a-z]?$") or sid:match("^[A-Z]+:%d+[a-z]?$")
end

-- returns the formatted short citation
function export.format(sid)
	if export.is_abbrev(sid) then
		if not sid:match(":%d+[a-z]?$") then
			local volume_number, preceding_author = sid:match(" %d+$"), sid:match("^.+%f[:]")
			if volume_number then sid = sid:gsub(volume_number.."$", "") end
			if preceding_author then sid = sid:gsub("^"..preceding_author..":", "") end
			sid = "''"..sid:gsub("%^(.+)", "<sup>%1</sup>").."''"
			if volume_number then sid = sid..volume_number end
			if preceding_author then sid = preceding_author.." "..sid end
			return sid
		else
			-- TODO: clarify situation, hacky solution
			return sid:gsub("^(.+):(%d+[a-z]?)$", "''%1'' (%2)")
		end
	else
		return sid:gsub("^(.+):(%d+[a-z]?)$", "%1 (%2)"):gsub("et al.", "''et al.''")
	end
end

-- returns the abbreviation without formatting characters to be used in links and parameters
function export.strip_markup(sid)
	if export.is_abbrev(sid) then
		return sid:gsub("%^", ""):gsub(":", " ")
	end
	return sid
end

-- returns the tracking path for sources
function export.tracking_path(lang, sid)
	return "bibliography/"..lang.."/"..sid
end

return export
Category:Templates and modules needing documentation Category:Uncategorized modules