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