Module:Motifs: Difference between revisions
From The Seven Sages of Rome
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 7: | Line 7: | ||
end | end | ||
local motifs = {} | local motifs = {} | ||
for motif in mw.text.gsplit(raw, ';', true) do | for motif in mw.text.gsplit(raw, ';', true) do | ||
motif = mw.text.trim(motif) | motif = mw.text.trim(motif) | ||
if motif ~= '' then | if motif ~= '' then | ||
table.insert(motifs, motif) | |||
table.insert(motifs, | |||
end | end | ||
end | end | ||
table.sort(motifs, function(a, b) | table.sort(motifs, function(a, b) | ||
return mw.ustring.lower(a) < mw.ustring.lower(b) | |||
end) | end) | ||
local html = mw.html.create() | local html = mw.html.create() | ||
for _, | for _, motif in ipairs(motifs) do | ||
html | |||
:tag('span') | :tag('span') | ||
:addClass('badge badge-pill badge-motif mr-1') | :addClass('badge badge-pill badge-motif mr-1') | ||
:wikitext(frame:preprocess( | |||
'{{#formredlink:target=' .. motif .. '|form=Content}}' | |||
)) | |||
end | end | ||
Latest revision as of 20:09, 24 April 2026
Documentation for this module may be created at Module:Motifs/doc
local p = {}
function p.renderBadges(frame)
local raw = frame.args[1] or ''
if raw == '' then
return ''
end
local motifs = {}
for motif in mw.text.gsplit(raw, ';', true) do
motif = mw.text.trim(motif)
if motif ~= '' then
table.insert(motifs, motif)
end
end
table.sort(motifs, function(a, b)
return mw.ustring.lower(a) < mw.ustring.lower(b)
end)
local html = mw.html.create()
for _, motif in ipairs(motifs) do
html
:tag('span')
:addClass('badge badge-pill badge-motif mr-1')
:wikitext(frame:preprocess(
'{{#formredlink:target=' .. motif .. '|form=Content}}'
))
end
return tostring(html)
end
return p