Module:Infobox: Difference between revisions

fix for {{infobox}} with no input args generating an empty <table class="infobox"></table> per talk page
m (1 revision imported)
(fix for {{infobox}} with no input args generating an empty <table class="infobox"></table> per talk page)
Line 5: Line 5:
local empty_row_categories = {}
local empty_row_categories = {}
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
local has_rows = false


local function fixChildBoxes(sval, tt)
local function fixChildBoxes(sval, tt)
Line 56: Line 57:
else
else
return sval
return sval
end
end
-- Cleans empty tables
local function cleanInfobox()
root = tostring(root)
if has_rows == false then
root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')
end
end
end
end
Line 94: Line 103:
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
has_rows = true
root
root
:tag('tr')
:tag('tr')
Line 115: Line 125:
category_in_empty_row_pattern, ''
category_in_empty_row_pattern, ''
):match('^%S') then
):match('^%S') then
has_rows = true
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(rowArgs.rowclass)
row:addClass(rowArgs.rowclass)
Line 147: Line 158:
if not args.title then return end
if not args.title then return end


has_rows = true
root
root
:tag('caption')
:tag('caption')
Line 159: Line 171:
if not args.above then return end
if not args.above then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
Line 173: Line 186:
if not args.below then return end
if not args.below then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
Line 187: Line 201:
if subheaderArgs.data and
if subheaderArgs.data and
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(subheaderArgs.rowclass)
row:addClass(subheaderArgs.rowclass)
Line 227: Line 242:
if imageArgs.data and
if imageArgs.data and
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
 
has_rows = true
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(imageArgs.rowclass)
row:addClass(imageArgs.rowclass)
Line 324: Line 340:
if not args.name then return end
if not args.name then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
Line 441: Line 458:
renderEmptyRowCategories()
renderEmptyRowCategories()
renderTrackingCategories()
renderTrackingCategories()
cleanInfobox()


return loadTemplateStyles() .. tostring(root)
return loadTemplateStyles() .. root
end
end


Anonymous user