Модуль:Loc/Marking: различия между версиями

Нет описания правки
Метка: отменено
Нет описания правки
Метка: отменено
Строка 90: Строка 90:
     if not s or s == "" then return s end
     if not s or s == "" then return s end
     local lines = mw.text.split(s, "\n")
     local lines = mw.text.split(s, "\n")
    local out_lines = {}


    -- Решаем, включать ли обработку числовых списков:
    local enable_numeric = false
    for _, line in ipairs(lines) do
        local line_unescaped = mw.ustring.gsub(line, " ", " ")
        if mw.ustring.match(line_unescaped, "^%s*%d+%.") then
            enable_numeric = true
            break
        end
    end
    local out_lines = {}
     for _, line in ipairs(lines) do
     for _, line in ipairs(lines) do
        local processed = line
         local handled = false
         local handled = false
         local line_unescaped = mw.ustring.gsub(line, " ", " ")
         local line_unescaped = mw.ustring.gsub(line, " ", " ")


         if enable_numeric then
         local leading, num, rest = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$")
            local leading, num, rest = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$")
        if num then
            if num then
            local indent = mw.ustring.len(leading or "")
                local indent = mw.ustring.len(leading or "")
            local level = math.floor(indent / 2)
                local level = math.floor(indent / 2)
            local hashes = string.rep('#', 1 + level) -- оставляем ваше поведение с '#'
                local hashes = string.rep('#', 1 + level)
            local processed = hashes .. (rest ~= "" and (" " .. rest) or "")
                processed = hashes .. (rest ~= "" and (" " .. rest) or "")
            table.insert(out_lines, processed)
                table.insert(out_lines, processed)
            handled = true
                handled = true
            end
         end
         end


         if not handled then
         if not handled then
             local leading, rest = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")
             local leading2, rest2 = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")
             if rest then
             if rest2 then
                 local indent = mw.ustring.len(leading or "")
                 local indent = mw.ustring.len(leading2 or "")
                 local level = math.floor(indent / 2)
                 local level = math.floor(indent / 2)
                 local hashes = string.rep('#', 1 + level)
                 local hashes = string.rep('#', 1 + level)
                 processed = hashes .. (rest ~= "" and (" " .. rest) or "")
                 local processed = hashes .. (rest2 ~= "" and (" " .. rest2) or "")
                 table.insert(out_lines, processed)
                 table.insert(out_lines, processed)
                 handled = true
                 handled = true
Строка 132: Строка 119:


         if not handled then
         if not handled then
             table.insert(out_lines, processed)
             table.insert(out_lines, line)
         end
         end
     end
     end
Строка 138: Строка 125:
     return table.concat(out_lines, "\n")
     return table.concat(out_lines, "\n")
end
end


local function transform(s)
local function transform(s)