Module:TemplateHelpers: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 210: | Line 210: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Formats website URLs as | -- 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 | ||
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 - | -- Single website case - create a single-item table | ||
websites = {value} | |||
else | |||
-- Multiple websites case | |||
websites = p.splitMultiValueString(value) | |||
end | end | ||
-- | -- Handle all websites consistently using the list format | ||
if #websites > 0 then | |||
if #websites > | |||
-- 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, "")) | ||
end | end | ||
return "" | return "" | ||
end | end | ||