Модуль:Песочница/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 | |||
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 | |||
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 | ||
| Строка 67: | Строка 95: | ||
local foundComponents = {} | local foundComponents = {} | ||
local foundPrototypes = {} | local foundPrototypes = {} | ||
local compList = componentDefs[id] | local compList = componentDefs[id] | ||
if type(compList) == "table" then | if type(compList) == "table" then | ||
| Строка 77: | Строка 104: | ||
end | end | ||
local protoList = prototypeDefs[id] | local protoList = prototypeDefs[id] | ||
if type(protoList) == "table" then | if type(protoList) == "table" then | ||
| Строка 87: | Строка 113: | ||
end | end | ||
for name in string.gmatch(id, "[^,]+") do | for name in string.gmatch(id, "[^,]+") do | ||
local n = trim(name) | local n = trim(name) | ||
if n ~= "" then | if n ~= "" then | ||
if componentDefs[n] ~= nil then | if componentDefs[n] ~= nil then | ||
foundComponents[n] = true | foundComponents[n] = true | ||
| Строка 98: | Строка 122: | ||
foundPrototypes[n] = true | foundPrototypes[n] = true | ||
end | end | ||
if componentDefs[n] == nil and prototypeDefs[n] == nil then | if componentDefs[n] == nil and prototypeDefs[n] == nil then | ||
foundComponents[n] = true | foundComponents[n] = true | ||
| Строка 152: | Строка 174: | ||
end | end | ||
for _, e in ipairs(errors) do | for _, e in ipairs(errors) do | ||
table.insert(out, "<div class=\"error\">" .. mw.text.encode(e) .. "</div>") | table.insert(out, "<div class=\"error\">" .. mw.text.encode(e) .. "</div>") | ||
end | end | ||
for _, key in ipairs(keyOrder) do | for _, key in ipairs(keyOrder) do | ||
table.insert(out, "<h2>" .. mw.text.encode(key) .. "</h2>") | table.insert(out, "<h2>" .. mw.text.encode(key) .. "</h2>") | ||