Модуль:Loc/Marking: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показана 1 промежуточная версия этого же участника) | |||
| Строка 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 .. '>' | |||
return '< | |||
elseif t == "font" then | elseif t == "font" then | ||
local family = params and params._value or nil | local family = params and params._value or nil | ||
| Строка 87: | Строка 84: | ||
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 | local stack = {} | ||
if | |||
local function make_prefix_from_stack() | |||
if #stack == 0 then return "" end | |||
return | return table.concat(stack, "") | ||
end | end | ||
for _, line in ipairs(lines) do | for _, line in ipairs(lines) do | ||
local line_unescaped = mw.ustring.gsub(line, " ", " ") | local line_unescaped = mw.ustring.gsub(line, " ", " ") | ||
local | local leading, num, rest_num = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$") | ||
local leading2, rest_dash = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$") | |||
if num then | |||
local indent = mw.ustring.len(leading or "") | |||
local level = math.floor(indent / indent_size) | |||
while #stack > level do table.remove(stack) end | |||
if #stack == level then | |||
table.insert(stack, "#") | |||
else | |||
table.insert( | while #stack < level do table.insert(stack, "#") end | ||
table.insert(stack, "#") | |||
end | end | ||
local prefix = make_prefix_from_stack() | |||
local text = rest_num or "" | |||
table.insert(out_lines, (prefix ~= "" and (prefix .. (text ~= "" and (" " .. text) or "")) or text)) | |||
elseif rest_dash then | |||
local indent = mw.ustring.len(leading2 or "") | |||
local level = math.floor(indent / indent_size) | |||
while #stack > level do table.remove(stack) end | |||
if #stack == level then | |||
table.insert(stack, "*") | |||
table.insert( | else | ||
while #stack < level do table.insert(stack, "*") end | |||
table.insert(stack, "*") | |||
end | end | ||
local prefix = make_prefix_from_stack() | |||
local text = rest_dash or "" | |||
table.insert(out_lines, (prefix ~= "" and (prefix .. (text ~= "" and (" " .. text) or "")) or text)) | |||
table.insert(out_lines, | else | ||
stack = {} | |||
table.insert(out_lines, line) | |||
end | end | ||
end | end | ||
| Строка 192: | Строка 194: | ||
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] | |||
text = mw.text.unstripNoWiki(text) | text = mw.text.unstripNoWiki(text) | ||
text = process_nowiki_equals(text) | text = process_nowiki_equals(text) | ||
return frame:preprocess('<div class="list-reset-margin">\n' .. transform(text) .. '</div>') | local class = format and "ts-loc-format" or "" | ||
return frame:preprocess( | |||
frame:extensionTag( | |||
'templatestyles', | |||
'', | |||
{ src = 'Модуль:Loc/styles.css' } | |||
) .. | |||
'<div class="list-reset-margin ' .. class .. '">\n' .. transform(text) .. '</div>' | |||
) | |||
end | end | ||
return p | return p | ||