Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 19: | Строка 19: | ||
if not content then return {} end | if not content then return {} end | ||
local keys = {} | local keys = {} | ||
local titlePos = | local lower = content:lower() | ||
local titlePos = lower:find("|%s*title%s*=") | |||
if not titlePos then | if not titlePos then | ||
return keys | return keys | ||
end | end | ||
local | -- find the first '{{' after the title position | ||
local | local startBrace = content:find("{{", titlePos) | ||
local | local region = nil | ||
if startBrace then | |||
local len = #content | |||
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 | ||