Модуль: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
     local function make_prefix(level, symbol)
    for _, line in ipairs(lines) do
         if level == 0 then
        local line_unescaped = mw.ustring.gsub(line, " ", " ")
             return symbol
         if mw.ustring.match(line_unescaped, "^%s*%d+%.") then
             enable_numeric = true
            break
         end
         end
        return ":" .. string.rep(symbol, level)
     end
     end


    local out_lines = {}
     for _, line in ipairs(lines) do
     for _, line in ipairs(lines) do
         local processed = line
         local processed = line
        local line_unescaped = mw.ustring.gsub(line, " ", " ")
         local handled = false
         local handled = false
        local line_unescaped = mw.ustring.gsub(line, " ", " ")


         if enable_numeric then
         do
             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 prefix = make_prefix(level, "#")
                 processed = hashes .. (rest ~= "" and (" " .. rest) or "")
                 processed = prefix .. (rest ~= "" and (" " .. rest) or "")
                 table.insert(out_lines, processed)
                 table.insert(out_lines, processed)
                 handled = true
                 handled = true
Строка 123: Строка 121:
                 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 prefix = make_prefix(level, "*")
                 processed = hashes .. (rest ~= "" and (" " .. rest) or "")
                 processed = prefix .. (rest ~= "" and (" " .. rest) or "")
                 table.insert(out_lines, processed)
                 table.insert(out_lines, processed)
                 handled = true
                 handled = true