Module:Sound: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| Line 21: | Line 21: | ||
-- CRITICAL FIX: The gsub removes the invisible newlines that force the icon to a new row | -- CRITICAL FIX: The gsub removes the invisible newlines that force the icon to a new row | ||
return tostring(container):gsub('[\n\r]', '') | return (tostring(container):gsub('[\n\r]', '')) | ||
end | end | ||
return p | return p | ||
Revision as of 14:33, 1 January 2026
Documentation for this module may be created at Module:Sound/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local fileName = mw.text.trim(args[1] or "")
local size = args[2] or '20px'
if fileName == '' then
return '<span style="color:red; font-weight:bold;">Error: No file specified</span>'
end
local fileUrl = mw.text.trim(frame:callParserFunction('filepath', fileName))
if fileUrl:sub(1,2) == "//" then fileUrl = "https:" .. fileUrl end
local container = mw.html.create('span')
:addClass('sound-button')
:attr('data-sound-file', fileUrl)
-- Added '|middle' to the file syntax for better text alignment
container:wikitext(string.format('[[File:Icon-Volume.png|%s|middle|link=]]', size))
-- CRITICAL FIX: The gsub removes the invisible newlines that force the icon to a new row
return (tostring(container):gsub('[\n\r]', ''))
end
return p