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

Нет описания правки
мНет описания правки
Строка 74: Строка 74:


local function convert_lists(s)
local function convert_lists(s)
    if not s or s == "" then return s end
     local lines = mw.text.split(s or "", "\n", true)
     local lines = mw.text.split(s, "\n")
     local out = {}
    local first_non_empty = nil
 
    for i, line in ipairs(lines) do
        if line and line:match("%S") then
            first_non_empty = line
            break
        end
    end
    local enable_numeric = false
    if first_non_empty and mw.ustring.match(first_non_empty, "^%s*%d+%.") then
        enable_numeric = true
    end
     local out_lines = {}
     for _, line in ipairs(lines) do
     for _, line in ipairs(lines) do
         local processed = line
         local indentEsc = mw.ustring.match(line, "^((  )*)") or ""
        local handled = false
        local level = 0
        local line_unescaped = mw.ustring.gsub(line, " ", " ")
 
         if enable_numeric then
         if indentEsc ~= "" then
             local leading, num, rest = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$")
             level = mw.ustring.len(indentEsc) / mw.ustring.len("  ")
            if num then
                local indent = mw.ustring.len(leading or "")
                local level = math.floor(indent / 2)
                local hashes = string.rep('#', 1 + level)
                processed = hashes .. (rest ~= "" and (" " .. rest) or "")
                table.insert(out_lines, processed)
                handled = true
            end
         end
         end
         if not handled then
 
            local leading, rest = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")
         local content = mw.ustring.sub(line, mw.ustring.len(indentEsc) + 1)
            if rest then
 
                local indent = mw.ustring.len(leading or "")
        local numMatch = mw.ustring.match(content, "^%d+%.%s*(.*)")
                 local level = math.floor(indent / 2)
        if numMatch then
                local stars = string.rep('*', 1 + level)
            table.insert(out, string.rep("#", level + 1) .. " " .. numMatch)
                processed = stars .. (rest ~= "" and (" " .. rest) or "")
        else
                 table.insert(out_lines, processed)
            local dashMatch = mw.ustring.match(content, "^%-%s*(.*)")
                handled = true
            if dashMatch then
                 table.insert(out, string.rep("*", level + 1) .. " " .. dashMatch)
            else
                 table.insert(out, line)
             end
             end
        end
        if not handled then
            table.insert(out_lines, processed)
         end
         end
     end
     end
     return table.concat(out_lines, "\n")
 
     return table.concat(out, "\n")
end
end


Строка 166: Строка 148:
     str = str:gsub('#', '#')
     str = str:gsub('#', '#')
             :gsub('=', '=')
             :gsub('=', '=')
 
            :gsub(' ', ' ')
             :gsub('{', '{')
             :gsub('{', '{')
             :gsub('"', '"')
             :gsub('"', '"')