Module:CountryData: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 525: Line 525:


     local ListGeneration = require('Module:ListGeneration')
     local ListGeneration = require('Module:ListGeneration')
    local itemsToProcess = {}
    -- First, check if the entire string is a single, valid country.
    -- This correctly handles names like "Trinidad and Tobago".
    local singleCountryName = CountryData.normalizeCountryName(value)
    if singleCountryName ~= "(Unrecognized)" then
        -- If it's a valid country, treat it as a single item.
        table.insert(itemsToProcess, value)
    else
        -- If not a single country, assume it's a list and split ONLY by semicolon.
        -- This is safer than letting ListGeneration guess the delimiter.
        for item in string.gmatch(value, "[^;]+") do
            local trimmed = item:match("^%s*(.-)%s*$")
            if trimmed and trimmed ~= "" then
                table.insert(itemsToProcess, trimmed)
            end
        end
    end


     -- Define the item hook for country-specific formatting
     -- Define the item hook for country-specific formatting
Line 547: Line 565:
     }
     }


     return ListGeneration.createList(value, options)
    -- Pass the pre-processed table of items to the list generator.
     return ListGeneration.createList(itemsToProcess, options)
end
end