Modul:Infobox: Perbedaan revisi

Loncat ke navigasi Loncat ke pencarian
343 bita dihapus ,  29 Juli 2021 16.48
k
1 revisi diimpor
Mediawiki>Frietjes
(fix for {{infobox}} with no input args generating an empty <table class="infobox"></table> per talk page)
k (1 revisi diimpor)
Baris 5: Baris 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)
Baris 57: Baris 56:
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
Baris 103: Baris 94:
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')
Baris 125: Baris 115:
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)
Baris 158: Baris 147:
if not args.title then return end
if not args.title then return end


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


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


has_rows = true
root
root
:tag('tr')
:tag('tr')
Baris 201: Baris 187:
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)
Baris 242: Baris 227:
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)
Baris 340: Baris 324:
if not args.name then return end
if not args.name then return end


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


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


Menu navigasi