Модуль:Поиск шаблона страницы: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}
local p = {}


Строка 8: Строка 6:


     searchText = searchText:match("^%s*(.-)%s*$")
     searchText = searchText:match("^%s*(.-)%s*$")
    searchText = searchText:gsub("<nowiki>", ""):gsub("</nowiki>", "")


     if searchText == "" then
     if searchText == "" then
Строка 21: Строка 20:
     local cleanedContent = content:gsub("{{#invoke:Поиск строк страницы|main|[^}]+}}", "")
     local cleanedContent = content:gsub("{{#invoke:Поиск строк страницы|main|[^}]+}}", "")


    local pattern = "([^%wА-Яа-яёЁ])" .. searchText .. "([^%wА-Яа-яёЁ])"
     if not cleanedContent:find(searchText, 1, true) then
   
     if not cleanedContent:match(pattern) then
         return "Нет"
         return "Нет"
     end
     end

Версия от 15:22, 6 марта 2025

Для документации этого модуля может быть создана страница Модуль:Поиск шаблона страницы/doc

local p = {}

function p.main(frame)
    local args = frame.args
    local searchText = args[1] or ""

    searchText = searchText:match("^%s*(.-)%s*$")
    searchText = searchText:gsub("<nowiki>", ""):gsub("</nowiki>", "")

    if searchText == "" then
        return "Нет"
    end

    local title = mw.title.getCurrentTitle()
    local content = title:getContent()
    if not content then
        return "Нет"
    end

    local cleanedContent = content:gsub("{{#invoke:Поиск строк страницы|main|[^}]+}}", "")

    if not cleanedContent:find(searchText, 1, true) then
        return "Нет"
    end

    return "Да"
end

return p