Модуль:Loc/Marking: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 74: | Строка 74: | ||
local function convert_lists(s) | local function convert_lists(s) | ||
local lines = mw.text.split(s | if not s or s == "" then return s end | ||
local lines = mw.text.split(s, "\n") | |||
local enable_numeric = false | |||
for _, line in ipairs(lines) do | for _, line in ipairs(lines) do | ||
if line and line:match("%S") then | |||
local | if mw.ustring.match(line, "^(?: )*%d+%. *") then | ||
enable_numeric = true | |||
end | |||
break | |||
end | |||
end | |||
local out_lines = {} | |||
for _, line in ipairs(lines) do | |||
local handled = false | |||
local leading = mw.ustring.match(line, "^((?: )*)") or "" | |||
local indent_spaces = select(2, leading:gsub(" ", "")) | |||
local level = math.floor(indent_spaces / 2) | |||
if enable_numeric then | |||
local rest = mw.ustring.match(line, "^(?: )*%d+%. *(.*)$") | |||
if rest then | |||
local hashes = string.rep('#', 1 + level) | |||
table.insert(out_lines, hashes .. (rest ~= "" and (" " .. rest) or "")) | |||
handled = true | |||
end | |||
end | end | ||
local | if not handled then | ||
local rest = mw.ustring.match(line, "^(?: )*%- +(.*)$") | |||
if rest then | |||
local stars = string.rep('*', 1 + level) | |||
table.insert(out_lines, stars .. (rest ~= "" and (" " .. rest) or "")) | |||
handled = true | |||
end | |||
end | |||
if not handled then | |||
if | table.insert(out_lines, line) | ||
table.insert( | |||
end | end | ||
end | end | ||
return table.concat( | return table.concat(out_lines, "\n") | ||
end | end | ||