Модуль: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") | ||
for | -- Решаем, включать ли обработку числовых списков: | ||
local enable_numeric = false | |||
for _, line in ipairs(lines) do | |||
local line_unescaped = mw.ustring.gsub(line, " ", " ") | |||
if mw.ustring.match(line_unescaped, "^%s*%d+%.") then | |||
enable_numeric = true | |||
break | break | ||
end | end | ||
end | end | ||
| Строка 129: | Строка 124: | ||
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 hashes = string.rep('#', 1 + level) | ||
processed = | processed = hashes .. (rest ~= "" and (" " .. rest) or "") | ||
table.insert(out_lines, processed) | table.insert(out_lines, processed) | ||
handled = true | handled = true | ||
| Строка 143: | Строка 138: | ||
return table.concat(out_lines, "\n") | return table.concat(out_lines, "\n") | ||
end | end | ||
local function transform(s) | local function transform(s) | ||
| Строка 190: | Строка 187: | ||
:gsub('=', '=') | :gsub('=', '=') | ||
:gsub(' ', ' ') | :gsub(' ', ' ') | ||
:gsub('{"', '') | |||
:gsub('"}', '') | |||
:gsub('{', '{') | :gsub('{', '{') | ||
:gsub('"', '"') | :gsub('"', '"') | ||
| Строка 200: | Строка 199: | ||
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 "" | ||
text = mw.text.unstripNoWiki(text) | text = mw.text.unstripNoWiki(text) | ||
text = process_nowiki_equals(text) | text = process_nowiki_equals(text) | ||
local parsed = frame:preprocess( | |||
frame:extensionTag('templatestyles', '', { src = 'Шаблон:Loc/styles.css' }) | |||
.. transform(text) | |||
) | |||
return '<div class="ts-loc-output">' .. parsed .. '</div>' | |||
end | end | ||
return p | return p | ||