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

мНет описания правки
Нет описания правки
 
(не показано 10 промежуточных версий этого же участника)
Строка 16: Строка 16:
     elseif t == "head" then
     elseif t == "head" then
         local level = params and tonumber(params._value) or 1
         local level = params and tonumber(params._value) or 1
         return '<h' .. level .. '>' .. inner .. '</h' .. level .. '>'
        level = math.max(1, math.min(3, level))
        local defaultSize = 100
        local size = math.ceil(defaultSize * 2 / math.sqrt(level))
         return '<span style="font-weight:bold; font-size:' .. size .. '%;">' .. inner .. '</span>'
     elseif t == "font" then
     elseif t == "font" then
         local family = params and params._value or nil
         local family = params and params._value or nil
Строка 84: Строка 87:
end
end


local function convert_lists(s)
local function convert_lists(s, indent_size)
    indent_size = indent_size or 2
     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 out_lines = {}


     local function make_prefix(level, symbol)
    local stack = {}
         if level == 0 then
 
            return symbol
     local function make_prefix_from_stack()
        end
         if #stack == 0 then return "" end
         return ":" .. string.rep(symbol, level)
         return table.concat(stack, "")
     end
     end


     for _, line in ipairs(lines) do
     for _, line in ipairs(lines) do
        local processed = line
         local line_unescaped = mw.ustring.gsub(line, "&#32;", " ")
         local line_unescaped = mw.ustring.gsub(line, "&#32;", " ")
         local handled = false
         local leading, num, rest_num = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$")
        local leading2, rest_dash = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")


         do
         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 / indent_size)
                local indent = mw.ustring.len(leading or "")
            while #stack > level do table.remove(stack) end
                local level = math.floor(indent / 2)
            if #stack == level then
                 local prefix = make_prefix(level, "#")
                 table.insert(stack, "#")
                 processed = prefix .. (rest ~= "" and (" " .. rest) or "")
            else
                 table.insert(out_lines, processed)
                 while #stack < level do table.insert(stack, "#") end
                handled = true
                 table.insert(stack, "#")
             end
             end
        end
            local prefix = make_prefix_from_stack()
 
            local text = rest_num or ""
        if not handled then
             table.insert(out_lines, (prefix ~= "" and (prefix .. (text ~= "" and (" " .. text) or "")) or text))
             local leading, rest = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$")
        elseif rest_dash then
            if rest then
            local indent = mw.ustring.len(leading2 or "")
                local indent = mw.ustring.len(leading or "")
            local level = math.floor(indent / indent_size)
                local level = math.floor(indent / 2)
            while #stack > level do table.remove(stack) end
                 local prefix = make_prefix(level, "*")
            if #stack == level then
                 processed = prefix .. (rest ~= "" and (" " .. rest) or "")
                 table.insert(stack, "*")
                 table.insert(out_lines, processed)
            else
                handled = true
                 while #stack < level do table.insert(stack, "*") end
                 table.insert(stack, "*")
             end
             end
        end
            local prefix = make_prefix_from_stack()
 
            local text = rest_dash or ""
         if not handled then
            table.insert(out_lines, (prefix ~= "" and (prefix .. (text ~= "" and (" " .. text) or "")) or text))
             table.insert(out_lines, processed)
         else
            stack = {}
             table.insert(out_lines, line)
         end
         end
     end
     end
Строка 145: Строка 153:
             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
         return "{{altTooltip|1=" .. (visible or "") .. "|2={{#invoke:Loc|GetRawString|" .. (tip or "") .. "}}}}"
         return "{{altTooltip|1=" .. (visible or "") .. "|2=<span style='white-space:pre-wrap;'>{{#invoke:Loc|GetRawString|noFormat=1|" .. (tip or "") .. "}}</span>}}"
     end)
     end)
     while true do
     while true do
Строка 189: Строка 197:
     local args = frame.args or {}
     local args = frame.args or {}
     local text = args[1] or args.text or ""
     local text = args[1] or args.text or ""
     local format = args[2]
     local noFormat = args.noFormat


     text = mw.text.unstripNoWiki(text)
     text = mw.text.unstripNoWiki(text)
     text = process_nowiki_equals(text)
     text = process_nowiki_equals(text)


     local class = format and "ts-loc-format" or ""
     local class = noFormat and "ts-loc-format" or ""
    local content = transform(text)
    if mw.ustring.find(content, '^[ \t]*[#%*;%:]+') then
        content = '\n' .. content
    end
 
     return frame:preprocess(
     return frame:preprocess(
         frame:extensionTag(
         frame:extensionTag(
Строка 201: Строка 214:
             { src = 'Модуль:Loc/styles.css' }
             { src = 'Модуль:Loc/styles.css' }
         ) ..
         ) ..
         '<div class="list-reset-margin ' .. class .. '">\n' .. transform(text) .. '</div>'
         '<span class="list-reset-margin ' .. class .. '">' .. content .. '</span>'
     )
     )
end
end


return p
return p