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

Нет описания правки
Метка: отменено
Нет описания правки
 
(не показано 7 промежуточных версий этого же участника)
Строка 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 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 = {}
     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, " ", " ")


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


         if not handled then
         if not handled then
             local leading2, rest2 = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")
             local leading, rest = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")
             if rest2 then
             if rest then
                 local indent = mw.ustring.len(leading2 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 .. (rest2 ~= "" and (" " .. rest2) or "")
                 processed = hashes .. (rest ~= "" and (" " .. rest) or "")
                 table.insert(out_lines, processed)
                 table.insert(out_lines, processed)
                 handled = true
                 handled = true
Строка 119: Строка 131:


         if not handled then
         if not handled then
             table.insert(out_lines, line)
             table.insert(out_lines, processed)
         end
         end
     end
     end
Строка 138: Строка 150:
             if tip == "" and params._value and visible ~= params._value then tip = params._value end
             if tip == "" and params._value and visible ~= params._value then tip = params._value end
         end
         end
        visible = mw.ustring.gsub(visible, "|", "|")
         return "{{altTooltip|1=" .. (visible or "") .. "|2={{#invoke:Loc|GetRawString|" .. (tip or "") .. "}}}}"
        tip = mw.ustring.gsub(tip, "|", "|")
         return "{{altTooltip|" .. (visible or "") .. "|{{#invoke:Loc|GetString|" .. (tip or "") .. "}}}}"
     end)
     end)
     while true do
     while true do
Строка 188: Строка 198:
     text = process_nowiki_equals(text)
     text = process_nowiki_equals(text)


     return frame:preprocess(transform(text))
     return frame:preprocess('<div class="list-reset-margin">\n' .. transform(text) .. '</div>')
end
end


return p
return p