Module:Sound

Revision as of 14:42, 1 January 2026 by Willow (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)

    container:wikitext(string.format('[[File:Icon-Volume.png|%s|middle|link=]]', size))

    return (tostring(container):gsub('[\n\r]', ''))
end

return p