Модуль: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 out_lines = {} | |||
local | local function make_prefix(level, symbol) | ||
if level == 0 then | |||
return symbol | |||
if | |||
end | end | ||
return ":" .. string.rep(symbol, level) | |||
end | end | ||
for _, line in ipairs(lines) do | for _, line in ipairs(lines) do | ||
local processed = line | local processed = line | ||
local line_unescaped = mw.ustring.gsub(line, " ", " ") | |||
local handled = false | local handled = false | ||
do | |||
local leading, num, rest = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$") | local leading, num, rest = mw.ustring.match(line_unescaped, "^(%s*)(%d+)%.%s*(.*)$") | ||
if num then | if num then | ||
local indent = mw.ustring.len(leading or "") | local indent = mw.ustring.len(leading or "") | ||
local level = math.floor(indent / 2) | local level = math.floor(indent / 2) | ||
local | local prefix = make_prefix(level, "#") | ||
processed = | processed = prefix .. (rest ~= "" and (" " .. rest) or "") | ||
table.insert(out_lines, processed) | table.insert(out_lines, processed) | ||
handled = true | handled = true | ||
| Строка 123: | Строка 121: | ||
local indent = mw.ustring.len(leading or "") | local indent = mw.ustring.len(leading or "") | ||
local level = math.floor(indent / 2) | local level = math.floor(indent / 2) | ||
local | local prefix = make_prefix(level, "*") | ||
processed = | processed = prefix .. (rest ~= "" and (" " .. rest) or "") | ||
table.insert(out_lines, processed) | table.insert(out_lines, processed) | ||
handled = true | handled = true | ||