Module:URL

From PS:1 Wiki Dev
Revision as of 00:04, 2 December 2025 by Rubin110 (talk | contribs) (Created page with "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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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