Модуль:Loc/Marking: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: отменено |
Pok (обсуждение | вклад) мНет описания правки Метка: отменено |
||
| Строка 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 first_non_empty = nil | |||
local first_non_empty_unescaped = nil | |||
for i, line in ipairs(lines) do | |||
if line and line:match("%S") then | |||
first_non_empty = line | |||
first_non_empty_unescaped = mw.ustring.gsub(line, " ", " ") | |||
break | |||
end | |||
end | |||
local enable_numeric = false | |||
if first_non_empty_unescaped and mw.ustring.match(first_non_empty_unescaped, "^%s*%d+%.") then | |||
enable_numeric = true | |||
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 | ||
local leading, num, rest = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$") | |||
if num then | |||
local indent = mw.ustring.len(leading or "") | |||
local level = math.floor(indent / 2) | |||
local hashes = string.rep('#', 1 + level) | |||
processed = hashes .. (rest ~= "" and (" " .. rest) or "") | |||
table.insert(out_lines, processed) | |||
handled = true | |||
end | |||
end | end | ||
if not handled then | if not handled then | ||
local | local leading, rest = mw.ustring.match(line_unescaped, "^(%s*)%-%s+(.*)$") | ||
if | if rest then | ||
local indent = mw.ustring.len( | local indent = mw.ustring.len(leading or "") | ||
local level = math.floor(indent / 2) | local level = math.floor(indent / 2) | ||
local | local stars = string.rep('#', 1 + level) | ||
processed = stars .. (rest ~= "" and (" " .. rest) or "") | |||
table.insert(out_lines, processed) | table.insert(out_lines, processed) | ||
handled = true | handled = true | ||
| Строка 119: | Строка 137: | ||
if not handled then | if not handled then | ||
table.insert(out_lines, | table.insert(out_lines, processed) | ||
end | end | ||
end | end | ||