Модуль:GetField: различия между версиями

Нет описания правки
Нет описания правки
Строка 446: Строка 446:


return templatePath
return templatePath
end
local function normalize_template_args(raw)
raw = mw.text.unstripNoWiki(raw or "")
if raw == "" then
return ""
end
if string.sub(raw, 1, 1) == "|" then
return string.sub(raw, 2)
end
return raw
end
end


local function split_template_spec(tplPath, tplArgs)
local function split_template_spec(tplPath, tplArgs)
tplPath = mw.text.unstripNoWiki(tplPath or "")
tplPath = mw.text.unstripNoWiki(tplPath or "")
tplArgs = normalize_template_args(tplArgs)
tplArgs = mw.text.unstripNoWiki(tplArgs or "")
if tplArgs ~= "" and string.sub(tplArgs, 1, 1) == "|" then
tplArgs = string.sub(tplArgs, 2)
end


if tplArgs == "" then
if tplArgs == "" then
local pipePos = string.find(tplPath, "|", 1, true)
local pipePos = string.find(tplPath, "|", 1, true)
if pipePos then
if pipePos then
tplArgs = normalize_template_args(string.sub(tplPath, pipePos + 1))
tplArgs = mw.text.unstripNoWiki(string.sub(tplPath, pipePos + 1))
if tplArgs ~= "" and string.sub(tplArgs, 1, 1) == "|" then
tplArgs = string.sub(tplArgs, 2)
end
tplPath = string.sub(tplPath, 1, pipePos - 1)
tplPath = string.sub(tplPath, 1, pipePos - 1)
end
end
Строка 489: Строка 482:
local entry = resolve_entry(data, id)
local entry = resolve_entry(data, id)
local extra = flatten_entry(entry)
local extra = flatten_entry(entry)
local extraTplArgs = normalize_template_args(tplArgs)
local extraTplArgs = tplArgs or ""


local templatePath = resolve_template_path(tplPath)
local templatePath = resolve_template_path(tplPath)
Строка 1047: Строка 1040:
local jsonStr = mw.text.unstripNoWiki(args[1] or args.json or "")
local jsonStr = mw.text.unstripNoWiki(args[1] or args.json or "")
local tplPath = mw.text.unstripNoWiki(args[2] or args.template or "")
local tplPath = mw.text.unstripNoWiki(args[2] or args.template or "")
local tplArgs = normalize_template_args(args[3] or args.tplArgs or args.templateArgs or "")
local tplArgs = args[3] or args.tplArgs or args.templateArgs or ""
tplPath, tplArgs = split_template_spec(tplPath, tplArgs)
tplPath, tplArgs = split_template_spec(tplPath, tplArgs)