Модуль:ISBN

Материал из HARITONOV
Перейти к: навигация, поиск

Для документации этого модуля может быть создана страница Модуль:ISBN/doc

local re = require "Module:Re"
	
local common = [==[
	control	<- digit / x
	digit	<- sep %d
	x		<- sep [xX] -> 'X'
	space	<- %s / ' '
	hyphen	<- '➖' / '−' / '-'/ '֊'/ '‐'/ '‑'/ '‒'/ '–'/ '—'/ '―'/ '⸺'/ '⸻'/ '﹘'/ '﹣'/ '-'
	sep		<- ( hyphen / space )? -> ''
	listsep	<- [,;] %s*
]==]

local function isbn (str, prefix, infix, suffix, property)
	local format = re.compile ([==[
		isbns	<- {~ isbn (listsep isbn)* ~}
		isbn	<- ( prefix space* )? -> '' {~ ( isbn13 / isbn10 ) ~} -> ']==] .. prefix .. '%1' .. infix .. '%0' .. suffix
	.. (property ~= '' and "{{#set:" .. property .. " = %1}}" or "") .. "'"
	.. [==[
		prefix	<- 'ISBN' / 'isbn'
		isbn13	<- digit^13
		isbn10	<- digit^9 control
	]==] .. common)
	local markedup = format:match (str)
	return markedup and '[[:ISBN]] ' .. markedup or ''
end		-- function local isbn (str, prefix, infix, suffix, property)
		
local function issn (str, prefix, infix, suffix, property)
	local format = re.compile ([==[
		issns	<- {~ issn (listsep issn)* ~}
		issn	<- ( prefix space* )? -> '' {~ issn8 ~} -> ']==] .. prefix .. '%1' .. infix .. '%0' .. suffix
	.. (property ~= '' and "{{#set:" .. property .. " = %1}}" or "") .. "'"
	.. [==[
		prefix	<- 'ISSN' / 'issn'
		issn8	<- digit^8
	]==] .. common)
	local markedup = format:match (str)
	return markedup and '[[:ISSN]] ' .. markedup or ''
end		-- local function issn (str, prefix, infix, suffix, property)

local function wrap (func, default_prefix, default_infix, default_suffix)
	return function (frame)
		local args = mw.clone (frame.args)
		local prefix	= args.prefix	or default_prefix
		local infix		= args.infix	or default_infix
		local suffix	= args.suffix	or default_suffix
		args.prefix, args.infix, args.suffix = nil, nil, nil
		local property = args.property or ''
		args.property = nil
		return frame:preprocess (func (table.concat (args, ', '), prefix, infix, suffix, property))
	end	-- return function (frame)
end	-- local function wrap (func, default_prefix, default_infix, default_suffix)

return {
	isbn = wrap (isbn, '[[Служебная:Источники книг/', '|', ']]')
  , issn = wrap (issn, '[https://www.worldcat.org/search?q=', ' ', ']')
}