Module:URL

From PS:1 Wiki Dev
Jump to navigationJump to search

Documentation for this module may be created at Module:URL/doc

Script error: Lua error: Internal error: The interpreter exited with status 127.

local p = {}

function p.url(frame)
    local args = frame:getParent().args
    local url = args[1] or ''
    local display = args[2] or ''
    
    if url == '' then
        return ''
    end
    
    -- Trim whitespace
    url = mw.text.trim(url)
    
    -- Add https:// if no protocol specified
    local fullUrl = url
    if not string.match(url, '^https?://') then
        fullUrl = 'https://' .. url
    end
    
    -- If no display text provided, strip protocol for display
    if display == '' then
        display = url
        display = string.gsub(display, '^https?://', '')
        display = string.gsub(display, '/$', '') -- Remove trailing slash
    end
    
    -- Return formatted link
    return '<span class="url">[' .. fullUrl .. ' ' .. display .. ']</span>'
end

return p