|
Метки: очистка ручная отмена |
| (не показаны 2 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {}
| |
|
| |
|
| function p.main(frame)
| |
| local args = frame:getParent().args
| |
|
| |
| -- Обработка и экранирование параметров
| |
| local name = mw.text.killMarkers(args.name or "Без названия")
| |
| local recipe = args.recipe or ""
| |
| local effects = frame:preprocess(args.effects or "Нет описания.")
| |
| local method = (recipe ~= "" and "Смешайте") or "Неизвестно"
| |
|
| |
| -- Функция для обработки реагентов (безопасная и с поддержкой запятых)
| |
| local function formatReagents(input)
| |
| if input == "" then return "" end
| |
|
| |
| local result = {}
| |
| -- Регулярка для обработки элементов вида "Название [10]"
| |
| for item, qty in mw.ustring.gmatch(input, "([^%[%],]-)%s*%[(%d+)%]%s*,?") do
| |
| item = mw.text.trim(item)
| |
| if item ~= "" then
| |
| table.insert(result, string.format(
| |
| '<div class="reagent-item">🧪 <span class="reagent">%s</span> <span class="qty">[%s]</span></div>',
| |
| mw.text.nowiki(item), qty
| |
| ))
| |
| end
| |
| end
| |
| return table.concat(result)
| |
| end
| |
|
| |
| -- Современное сворачивание без JavaScript
| |
| local function makeCollapsible(title, body)
| |
| return string.format([[
| |
| <details class="alchemy-collapsible">
| |
| <summary>%s</summary>
| |
| <div class="alchemy-collapsible-content">%s</div>
| |
| </details>]], title, body)
| |
| end
| |
|
| |
| -- Сборка HTML-карточки
| |
| local html = {
| |
| '<div class="alchemy-card">',
| |
| '<div class="alchemy-title">' .. name .. '</div>',
| |
| '<div class="alchemy-section">',
| |
| makeCollapsible("Рецепт", formatReagents(recipe) .. '<div class="method">🔄 ' .. method .. '</div>'),
| |
| '</div>',
| |
| '<div class="alchemy-section">',
| |
| makeCollapsible("Эффекты", effects),
| |
| '</div>',
| |
| '</div>'
| |
| }
| |
|
| |
| return table.concat(html)
| |
| end
| |
|
| |
| return p
| |