Module:Infobox: Difference between revisions

1,383 bytes added ,  7 years ago
merge from sandbox; still some pages with odd infoboxes over the place because of Tidy
m>Frietjes
(Undid revision 782833995 by Jc86035 (talk) looks like this caused some serious problems, will require more testing (see, e.g, my talk page))
m>Jc86035
(merge from sandbox; still some pages with odd infoboxes over the place because of Tidy)
Line 10: Line 10:
local origArgs
local origArgs
local root
local root
local function notempty( s ) return s and s:match( '%S' ) end
local function fixChildBoxes(sval, tt)
if notempty(sval) then
local marker = '<span class=special_infobox_marker>'
local s = sval
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
if s:match(marker) then
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s,  marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
end
if s:match(marker) then
local subcells = mw.text.split(s, marker)
s = ''
for k = 1, #subcells do
if k == 1 then
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
elseif k == #subcells then
local rowstyle = ' style="display:none"'
if notempty(subcells[k]) then rowstyle = '' end
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' .. subcells[k]
elseif notempty(subcells[k]) then
if (k % 2) == 0 then
s = s .. subcells[k]
else
s = s .. '<tr><' .. tt .. ' colspan=2>\n' .. subcells[k] .. '</' .. tt .. '></tr>'
end
end
end
end
return s
else
return sval
end
end


local function union(t1, t2)
local function union(t1, t2)
Line 57: Line 96:
                     :cssText(args.headerstyle)
                     :cssText(args.headerstyle)
                     :cssText(rowArgs.rowcellstyle)
                     :cssText(rowArgs.rowcellstyle)
                     :wikitext(rowArgs.header)
                     :wikitext(fixChildBoxes(rowArgs.header, 'th'))
     elseif rowArgs.data then
     elseif rowArgs.data then
         local row = root:tag('tr')
         local row = root:tag('tr')
Line 86: Line 125:
             :cssText(rowArgs.rowcellstyle)
             :cssText(rowArgs.rowcellstyle)
             :newline()
             :newline()
             :wikitext(rowArgs.data)
             :wikitext(fixChildBoxes(rowArgs.data, 'td'))
     end
     end
end
end
Line 112: Line 151:
                 :css('font-weight', 'bold')
                 :css('font-weight', 'bold')
                 :cssText(args.abovestyle)
                 :cssText(args.abovestyle)
                 :wikitext(args.above)
                 :wikitext(fixChildBoxes(args.above,'th'))
end
end


Line 126: Line 165:
                 :cssText(args.belowstyle)
                 :cssText(args.belowstyle)
                 :newline()
                 :newline()
                 :wikitext(args.below)
                 :wikitext(fixChildBoxes(args.below,'td'))
end
end


Anonymous user