توضیحات پودمان[ایجاد] [پاکسازی]
-- Tools for [[Template:Cite doi]].
local p = {}

---Returns the ASCII character represented by the given hexadecimal string.
-- This function returns no value when the hexadecimal string represents a
-- control character.
function charFromHexStr(hexStr)
	local hex = tonumber(hexStr, 16)
	local char = hex and string.char(hex)
	if not char:match("%c") then return char end
end

---Decodes the given anchor-encoded string, more or less reversing the effect of
-- anchorencode: on a string.
-- The anchorencode: parser function is lossy. That is, "/" and ".2F" are both
-- encoded as ".2F", which this function converts to "/" regardless.
-- This function is intended as a drop-in replacement for the conversion from
-- doix to doi that [[User:Citation bot]] performs.
-- <https://code.google.com/p/citation-bot/source/browse/trunk/objects.php#1782>
-- <https://code.google.com/p/citation-bot/source/browse/trunk/citewatch.php#14>
function p.anchordecode(frame)
	local anchor = (frame.args and frame.args[1]) or frame
	return (anchor:gsub("%.(%x%x)", charFromHexStr):gsub("_", " "))
end

---Returns the DOI at the end of the current page's title.
function p.currentdoi(frame)
	local title = mw.title.getCurrentTitle()
	local doix = mw.ustring.gsub(title.text, "^" .. title.rootText .. "/", "", 1)
	return p.anchordecode(doix)
end

return p