Modul:Smiles: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
Nema sažetka uređivanja |
mNema sažetka uređivanja |
||
| Redak 1: | Redak 1: | ||
local p = {} | local p = {} | ||
-- funkcija koja čisti parametre koje MediaWiki krivo interpretira | |||
local function sanitize(v) | |||
if not v then return nil end | |||
-- ukloni nevidljive Unicode razmake i kontrolne znakove | |||
v = mw.ustring.gsub(v, "[\226\128\139\194\160]", "") | |||
v = mw.text.trim(v) | |||
if v == "" then return nil end | |||
return v | |||
end | |||
function p.render(frame) | function p.render(frame) | ||
| Redak 5: | Redak 15: | ||
local par = frame:getParent() and frame:getParent().args or {} | local par = frame:getParent() and frame:getParent().args or {} | ||
-- | -- pokušaj svih mogućih izvora | ||
local smiles = args[1] or args.smiles or par[1] or par.smiles | local smiles = | ||
sanitize(args[1]) or | |||
sanitize(args.smiles) or | |||
sanitize(par[1]) or | |||
sanitize(par.smiles) | |||
-- fallback: ako MediaWiki pogrešno interpretira "C1=CC=CC=C1" kao "C1" | |||
if not smiles then | |||
for k, v in pairs(args) do | |||
if type(k) == "string" and mw.ustring.match(k, "^C%d") then | |||
smiles = k .. "=" .. v | |||
end | |||
end | |||
end | |||
if not smiles | if not smiles then | ||
return | return "[SMILES nije naveden]" | ||
end | end | ||
-- opcije | -- opcije | ||
local size = tonumber(args.size or par.size) or 260 | local size = tonumber(args.size or par.size) or 260 | ||
local theme = (args.theme or par.theme or | local theme = (args.theme or par.theme or "light"):lower() | ||
local svg = (args.svg or par.svg or | local svg = (args.svg or par.svg or ""):lower() | ||
if theme ~= "light" and theme ~= "dark" then | |||
if theme ~= | theme = "light" | ||
theme = | |||
end | end | ||
local html = mw.html.create("div") | |||
local html = mw.html.create( | :addClass("mw-smiles") | ||
:addClass( | :attr("data-smiles", smiles) | ||
:attr( | :attr("data-size", size) | ||
:attr( | :attr("data-theme", theme) | ||
:attr( | :attr("data-svg", svg) | ||
:attr( | |||
return tostring(html) | return tostring(html) | ||
Inačica od 20. svibanj 2026. u 12:04
local p = {}
-- funkcija koja čisti parametre koje MediaWiki krivo interpretira
local function sanitize(v)
if not v then return nil end
-- ukloni nevidljive Unicode razmake i kontrolne znakove
v = mw.ustring.gsub(v, "[\226\128\139\194\160]", "")
v = mw.text.trim(v)
if v == "" then return nil end
return v
end
function p.render(frame)
local args = frame.args
local par = frame:getParent() and frame:getParent().args or {}
-- pokušaj svih mogućih izvora
local smiles =
sanitize(args[1]) or
sanitize(args.smiles) or
sanitize(par[1]) or
sanitize(par.smiles)
-- fallback: ako MediaWiki pogrešno interpretira "C1=CC=CC=C1" kao "C1"
if not smiles then
for k, v in pairs(args) do
if type(k) == "string" and mw.ustring.match(k, "^C%d") then
smiles = k .. "=" .. v
end
end
end
if not smiles then
return "[SMILES nije naveden]"
end
-- opcije
local size = tonumber(args.size or par.size) or 260
local theme = (args.theme or par.theme or "light"):lower()
local svg = (args.svg or par.svg or ""):lower()
if theme ~= "light" and theme ~= "dark" then
theme = "light"
end
local html = mw.html.create("div")
:addClass("mw-smiles")
:attr("data-smiles", smiles)
:attr("data-size", size)
:attr("data-theme", theme)
:attr("data-svg", svg)
return tostring(html)
end
return p