Module:Infobox: Difference between revisions
m
1 revision imported from wikipedia:Module:Infobox
(add using-infobox tstyles support) |
m (1 revision imported from wikipedia:Module:Infobox) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 5:
local empty_row_categories = {}
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)
Line 12 ⟶ 13:
local marker = '<span class=special_infobox_marker>'
local s = sval
-- start moving templatestyles and categories inside of table rows
local slast = ''
while slast ~= s do
slast = s
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*%]%])', '%2%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1')
end
-- end moving templatestyles and categories inside of table rows
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
Line 56 ⟶ 65:
else
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
Line 94 ⟶ 111:
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
has_rows = true
root
:tag('tr')
Line 113 ⟶ 131:
end
elseif rowArgs.data and rowArgs.data:gsub(
category_in_empty_row_pattern, ''
):match('^%S') then
has_rows = true
local row = root:tag('tr')
row:addClass(rowArgs.rowclass)
Line 147 ⟶ 166:
if not args.title then return end
has_rows = true
root
:tag('caption')
Line 159 ⟶ 179:
if not args.above then return end
has_rows = true
root
:tag('tr')
Line 173 ⟶ 194:
if not args.below then return end
has_rows = true
root
:tag('tr')
Line 187 ⟶ 209:
if subheaderArgs.data and
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
local row = root:tag('tr')
row:addClass(subheaderArgs.rowclass)
Line 227 ⟶ 250:
if imageArgs.data and
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
local row = root:tag('tr')
row:addClass(imageArgs.rowclass)
Line 324 ⟶ 348:
if not args.name then return end
has_rows = true
root
:tag('tr')
Line 369 ⟶ 394:
Loads the templatestyles for the infobox.
TODO:
When we do this we should clean up the inline CSS below too.
Will have to do some bizarre conversion category like with sidebar.
]=]
local function loadTemplateStyles()
local frame = mw.getCurrentFrame()
-- See function description
local templatestyles = ''
if args['templatestyles'] then templatestyles = frame:extensionTag{
Line 403 ⟶ 428:
return table.concat({
templatestyles,
child_templatestyles,
grandchild_templatestyles
})
end
-- common functions between the child and non child cases
local function structure_infobox_common()
renderSubheaders()▼
renderImages()▼
preprocessRows()▼
renderRows()▼
renderBelowRow()▼
renderNavBar()▼
renderItalicTitle()▼
renderEmptyRowCategories()▼
renderTrackingCategories()▼
cleanInfobox()
end
Line 431 ⟶ 469:
:wikitext(args.title)
end
structure_infobox_common()
▲ renderSubheaders()
▲ renderImages()
▲ preprocessRows()
▲ renderRows()
▲ renderBelowRow()
▲ renderNavBar()
▲ renderItalicTitle()
▲ renderEmptyRowCategories()
▲ renderTrackingCategories()
▲ return loadTemplateStyles() .. tostring(root)
end
|