Модуль:Новости: различия между версиями
Материал из AbduloverA.com
![]() Adept (обсуждение | вклад) |
![]() Adept (обсуждение | вклад) |
||
Строка 7: | Строка 7: | ||
local pageName = "Шаблон:Новости" | local pageName = "Шаблон:Новости" | ||
local content = mw.title.new(pageName):getContent() | local content = mw.title.new(pageName):getContent() | ||
if not content then | |||
return "Страница не найдена или пуста." | |||
end | |||
-- Парсинг строк таблицы | -- Парсинг строк таблицы | ||
local rows = {} | |||
-- for row in content:gmatch("|%s*[%w%W]-|%-") do | -- for row in content:gmatch("|%s*[%w%W]-|%-") do | ||
-- | for row in content:gmatch("%s*, <td>") do | ||
-- table.insert(rows, row) | |||
mw.log(row); | |||
end | |||
-- -- Вывод первых 5 строк | -- -- Вывод первых 5 строк |
Версия от 02:09, 26 декабря 2024
Для документации этого модуля может быть создана страница Модуль:Новости/doc
local p = {} function p.render(frame) -- mw.log("Entering") -- Получение содержимого страницы с таблицей -- local pageName = frame.args[1] or "Шаблон:Новости" local pageName = "Шаблон:Новости" local content = mw.title.new(pageName):getContent() if not content then return "Страница не найдена или пуста." end -- Парсинг строк таблицы local rows = {} -- for row in content:gmatch("|%s*[%w%W]-|%-") do for row in content:gmatch("%s*, <td>") do -- table.insert(rows, row) mw.log(row); end -- -- Вывод первых 5 строк -- local result = {} -- for i = 1, math.min(5, #rows) do -- table.insert(result, rows[i]) -- print("This"); -- end -- return table.concat(result, "\n") end return p