Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показаны 2 промежуточные версии этого же участника) | |||
| Строка 319: | Строка 319: | ||
return s | return s | ||
end | end | ||
local text = tostring(s) | |||
local replacement | |||
if repl and repl ~= "" then | |||
replacement = tostring(repl) | |||
replacement = replacement:gsub("\\(%d)", "%%%1") | |||
else | |||
replacement = "%1" | |||
end | |||
local patt = pattern | |||
if not patt:find("%^") and not patt:find("%$") then | |||
patt = "^" .. patt .. "$" | |||
end | |||
return (text:gsub(patt, replacement)) | |||
end | end | ||
| Строка 332: | Строка 347: | ||
end | end | ||
local bullet = args.prefix or "* " | local bullet = mw.text.unstripNoWiki(args.prefix or "* ") | ||
local sep = args.sep or ": " | local sep = mw.text.unstripNoWiki(args.sep or ": ") | ||
local keyPattern = args.key_pattern | local keyPattern = mw.text.unstripNoWiki(args.key_pattern or "(.*)") | ||
local keyReplace = args.key_replace | local keyReplace = mw.text.unstripNoWiki(args.key_replace or "\\1") | ||
local valuePattern = args.value_pattern | local valuePattern = mw.text.unstripNoWiki(args.value_pattern or "(.*)") | ||
local valueReplace = args.value_replace | local valueReplace = mw.text.unstripNoWiki(args.value_replace or "\\1") | ||
local out = {} | local out = {} | ||
| Строка 365: | Строка 380: | ||
end | end | ||
if text ~= "" then | if text ~= "" then | ||
text = apply_pattern(text, | local patt = valuePattern ~= "" and valuePattern or keyPattern | ||
local repl = valueReplace ~= "" and valueReplace or keyReplace | |||
text = apply_pattern(text, patt, repl) | |||
table.insert(out, bullet .. text) | table.insert(out, bullet .. text) | ||
end | end | ||