Module:SemanticCategoryHelpers: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 77: | Line 77: | ||
-- Category Utilities | -- Category Utilities | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Ensures a category string is properly wrapped in MediaWiki syntax | |||
function p.formatCategoryName(categoryName) | |||
if not categoryName or categoryName == "" then return "" end | |||
-- Already has full MediaWiki syntax | |||
if categoryName:match("^%[%[Category:[^%]]+%]%]$") then | |||
return categoryName | |||
end | |||
-- Has partial syntax, normalize it | |||
if categoryName:match("^Category:") then | |||
return string.format("[[%s]]", categoryName) | |||
end | |||
-- Plain category name, add full syntax | |||
return string.format("[[Category:%s]]", categoryName) | |||
end | |||
-- Builds a category string from a table of category names | -- Builds a category string from a table of category names | ||
| Line 88: | Line 106: | ||
for _, cat in ipairs(categories) do | for _, cat in ipairs(categories) do | ||
-- | -- Use the formatCategoryName function to ensure proper syntax | ||
formatted[index] = p.formatCategoryName(cat) | |||
index = index + 1 | index = index + 1 | ||
end | end | ||