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 decorated = prefix .. '%1' .. infix .. '%0' .. suffix
.. (property ~= '' and "{{#set:" .. property .. " = %1}}" or "") .. "'"
local format = re.compile ([==[
isbns <- {~ isbn (listsep isbn)* ~}
isbn <- ( prefix space* )? -> '' {~ ( isbn13 / isbn10 ) ~} -> ']==] .. decorated
.. [==[
prefix <- 'ISBN' / 'isbn'
isbn10 <- isbn9 control9
isbn13 <- ( '978' / '979' ) isbn9 control13
isbn9 <- digit^9
control9 <- control
control13 <- digit
]==] .. 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 decorated = prefix .. '%1' .. infix .. '%0' .. suffix
.. (property ~= '' and "{{#set:" .. property .. " = %1}}" or "") .. "'"
local format = re.compile ([==[
issns <- {~ issn (listsep issn)* ~}
issn <- ( prefix space* )? -> '' {~ issn8 ~} -> ']==] .. decorated
.. [==[
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=', ' ', ']')
}