Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 19: Строка 19:
if not content then return {} end
if not content then return {} end
local keys = {}
local keys = {}
local lower = content:lower()
local titlePos = string.find(content, "|%s*title%s*=")
local titlePos = lower:find("|%s*title%s*=")
if not titlePos then
if not titlePos then
return keys
return keys
end
end
-- find the first '{{' after the title position
local substr = content:sub(titlePos)
local startBrace = content:find("{{", titlePos)
local endPos = substr:find("}}")
local region = nil
local region = substr
if startBrace then
if endPos then
local len = #content
region = substr:sub(1, endPos)
local i = startBrace
local depth = 0
while i <= len - 1 do
local two = content:sub(i, i+1)
if two == "{{" then
depth = depth + 1
i = i + 2
elseif two == "}}" then
depth = depth - 1
i = i + 2
if depth == 0 then
region = content:sub(startBrace, i-1)
break
end
else
i = i + 1
end
end
end
if not region then
-- fallback: take substring from titlePos to next '}}'
local substr = content:sub(titlePos)
local endPos = substr:find("}}")
if endPos then
region = substr:sub(1, endPos)
else
region = substr
end
end
end
for key in string.gmatch(region, "|%s*([^=|%}]-)%s*=") do
for key in string.gmatch(region, "|%s*([^=|%}]-)%s*=") do