Module:TemplateHelpers: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 210: Line 210:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- Formats website URLs as either a single link or an HTML unordered list of links
-- Formats website URLs as an HTML unordered list of links, ensuring consistent emoji display
-- Uses splitMultiValueString for more flexible delimiter handling
-- Uses splitMultiValueString for more flexible delimiter handling
-- Optimized to avoid unnecessary table creation for single websites
function p.normalizeWebsites(value)
function p.normalizeWebsites(value)
     if not value or value == "" then return "" end
     if not value or value == "" then return "" end
   
    -- Get websites as a table, handling both single and multiple cases
    local websites
      
      
     -- Quick check for single website (no delimiters)
     -- Quick check for single website (no delimiters)
     if not value:match(";") and not value:match("%s+and%s+") then
     if not value:match(";") and not value:match("%s+and%s+") then
         -- Single website case - avoid table creation entirely
         -- Single website case - create a single-item table
         return string.format("[%s %s]", value, linkParser.strip(value))
         websites = {value}
    else
        -- Multiple websites case
        websites = p.splitMultiValueString(value)
     end
     end
      
      
     -- Multiple websites case
     -- Handle all websites consistently using the list format
    local websites = p.splitMultiValueString(value)
     if #websites > 0 then
     if #websites > 1 then
         -- Pre-allocate listItems table based on number of websites
         -- Pre-allocate listItems table based on number of websites
         local listItems = {}
         local listItems = {}
Line 235: Line 239:
         end
         end
         return string.format("<ul class=\"template-list template-list-website\" style=\"margin:0; padding-left:1em;\">%s</ul>", table.concat(listItems, ""))
         return string.format("<ul class=\"template-list template-list-website\" style=\"margin:0; padding-left:1em;\">%s</ul>", table.concat(listItems, ""))
    elseif #websites == 1 then
        return string.format("[%s %s]", websites[1], linkParser.strip(websites[1]))
     end
     end
   
     return ""
     return ""
end
end