Module:Sports series: Difference between revisions

Content deleted Content added
allow for grey cell
improvements: fix pattern matching, auto generate small font size for future matches, remove unnecessary text-align:center, directly generate abbr code
Line 41:
else
return n .. 'th'
end
end
 
-- Function to replace wiki links with their display text or link text
local function replaceLink(match)
local pipePos = match:find("|")
if pipePos then
return match:sub(pipePos + 1, -3) -- Return text after the '|'
else
return match:sub(3, -3) -- Return text without the brackets
end
end
Line 49 ⟶ 59:
if not score or score:match("^%s*$") then
return ''
end
 
-- Function to replace wiki links with their display text or link text
local function replaceLink(match)
local pipePos = match:find("|")
if pipePos then
return match:sub(pipePos + 1, -3) -- Return text after the '|'
else
return match:sub(3, -3) -- Return text without the brackets
end
end
 
Line 65:
 
-- Remove MediaWiki's unique placeholder sequences for references
score = score:gsub('\127%\'"`UNIQ.-QINU`"%\'\127', '')
 
-- Remove superscript tags and their contents
Line 71:
 
-- Convert dashes to a standard format
score = score:gsub('[–—―‒−]+', '-')
 
-- Strip all characters except numbers, dashes and parentheses
Line 200:
:css('margin-bottom', '0.5em')
:wikitext("Legend: Blue = home team win; Yellow = draw; Red = away team win.")
end
 
-- Function to check whether to reduce font size for upcoming matches
local function checkSmallText(str)
-- Check for font size or small/big HTML tags
if str:match("font%s?%-?size") or str:match("<small>") or str:match("<big>") then
return false
end
 
-- Remove MediaWiki's unique placeholder sequences for references
str = str:gsub('\127%\'"`UNIQ.-QINU`"%\'\127', '')
 
-- Remove superscript tags and their contents
str = str:gsub('<sup.->.-</sup>', '')
 
-- Replace wiki links with their display text or link text
str = str:gsub("%[%[.-%]%]", replaceLink)
 
-- Remove all text inside parentheses
str = str:gsub("%b()", "")
 
if str == "—" or str == "–" then
return false
end
 
-- Convert dashes to a standard format
str = str:gsub('[–—―‒−]+', '-')
 
-- Remove opening and closing HTML tags
str = str:gsub("</?%w+[^>]*>", "")
 
-- Remove all whitespace
str = str:gsub("%s+", "")
 
-- Check if the string matches only a scoreline
if str:match("^%d+-%d+$") then
return false
else
return true
end
end
 
Line 245 ⟶ 285:
 
-- Process the font size parameter
local sizefontSize
if args.font_size then
-- Remove trailing '%' if present and convert to number
sizefontSize = tonumber((args.font_size:gsub('%s*%%$', '')))
if sizefontSize then
sizefontSize = math.max(sizefontSize, 85) -- Ensure font size is at least 85
end
end
-- Calculate the font size for small text
local smallFontSize
if fontSize then
smallFontSize = math.floor(((fontSize / 100) * 0.85) * 100)
else
smallFontSize = 85
end
 
Line 300 ⟶ 347:
local isHA = args.h_a == 'y' or args.h_a == 'yes' or args.h_a == '1' or args.h_a == 'true'
local disableAwayGoals = args.away_goals == 'n' or args.away_goals == 'no' or args.away_goals == '0' or args.away_goals == 'false' or args.away_goals == 'null'
local disableSmallText = args.small_text == 'n' or args.small_text == 'no' or args.small_text == '0' or args.small_text == 'false' or args.small_text == 'null'
 
local tableClass = 'wikitable'
Line 305 ⟶ 353:
if args.collapsed and (args.collapsed == 'y' or args.collapsed == 'yes' or args.collapsed == '1' or args.collapsed == 'true') then
tableClass = 'wikitable mw-collapsible mw-collapsed'
tableStyle = tableStyle .. ' width: 100%; text-align: center;'
end
if args.nowrap and (args.nowrap == 'y' or args.nowrap == 'yes' or args.nowrap == '1' or args.nowrap == 'true') then
tableStyle = tableStyle .. ' white-space: nowrap;'
end
if sizefontSize then
tableStyle = tableStyle .. ' font-size: ' .. sizefontSize .. '%;'
end
 
Line 342 ⟶ 390:
:attr('colspan', colCount)
:attr('scope', 'colgroup')
:css('text-align', 'center')
:wikitext(args.title)
end
Line 358 ⟶ 405:
:attr('scope', 'col')
:css('width', scoreWidth)
:wikitext(args['aggregate'] or legs == 0 and 'Score' or expandTemplate'[[Aggregate score|<abbr title="Aggregate score">Agg.</abbr>]]<span class="sr-only" style="border: 0; clip: rect(frame0, 'Abbrlink'0, {'Agg.'0, '0); clip-path: polygon(0px 0px, 0px 0px, 0px 0px); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; white-space: nowrap;">Tooltip Aggregate score</span>'}))
header:tag('th')
:attr('scope', 'col')
Line 407 ⟶ 454:
headingRow:tag('td')
:attr('colspan', colCount)
:css('text-align', 'center')
:css('background', 'whitesmoke')
:wikitext('<strong>' .. headingParam .. '</strong>')
Line 515 ⟶ 561:
 
-- Create aggregate score cell with conditional styling
local aggregateStyle = 'text-align: center;'
if legs == 0 and not disableSmallText and checkSmallText(aggregateScore) then
aggregateStyle = 'font-size: ' .. smallFontSize .. '%;'
end
if isFBRStyle and legs == 0 then
if team1Winner then
aggregateStyle = aggregateStyle .. '; background-color: #BBF3FF;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBB;'
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
 
-- Create rows for aggregate score and team names, bolded if set by user
row:tag('td'):cssText(team1Style):wikitext((team1Winner and (boldWinner or manualBold) and team1Text ~= '') and ('<strong>' .. team1Text .. '</strong>') or team1Text)
row:tag('td'):cssText(aggregateStyle ~= '' and aggregateStyle or nil):wikitext(aggregateScore)
row:tag('td'):cssText(team2Style):wikitext((team2Winner and (boldWinner or manualBold) and team2Text ~= '') and ('<strong>' .. team2Text .. '</strong>') or team2Text)
 
Line 543 ⟶ 592:
row:tag('td'):css('background', '#BBBBBB')
else
row:tag('td'):css('text-align', 'center'):wikitext('—')
end
else
Line 550 ⟶ 599:
if baselink ~= '' then
legScore = rewriteAnchorLinks(legScore, baselink)
end
local legStyle = ''
if not disableSmallText and checkSmallText(legScore) then
legStyle = 'font-size: ' .. smallFontSize .. '%;'
end
-- Write cells for legs
row:tag('td'):csscssText('text-align',legStyle ~= 'center' and legStyle or nil):wikitext(legScore)
end
end