Content deleted Content added
and there |
S.A. Julio (talk | contribs) improve link rewriting |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 257:
-- Check for walkover-related strings (never shown in small text)
if str:lower():match("walkover") or str:lower():match("w%.o%.") or str:lower():match("w/o") or str:lower():match("bye") then
return false
end
Line 290:
return true
end
-- Function to rewrite anchor links in a string
local function rewriteAnchorLinks(str, baselink, currentPageTitle)
return str
end
-- Add the base link to anchor links when the module is transcluded on another page
if baselink ~= '' then
end
-- Remove redundant page references when viewing anchors on the current page
if currentPageTitle and currentPageTitle ~= "" then
local escapedTitle = currentPageTitle:gsub("([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1")▼
local titlePattern = '%[%[' .. escapedTitle .. '(#[^%[%]]*%|)'▼
end
return str
end
Line 295 ⟶ 316:
local function format_and_extract_score(s, addSpan)
if not s then return '', '' end -- Return empty strings if input is nil
-- Handle walkovers
if s:match("^%s*[Ww]%s*[/.]%s*[Oo]%s*%.?%s*$") then
return "[[Walkover|w/o]]", ""
end
local function format_dash(pattern)
Line 359 ⟶ 385:
if endText ~= "" then
if addSpan then
endText = mw.ustring.gsub(endText, '(%(%d+%s*–%s*%d+)%s
endText = mw.ustring.gsub(endText, '%([Aa]%.?[Ee]%.?[Tt]%.?%)', '<span class="nowrap">([[Overtime (sports)#Association football|a.e.t.]])</span>')
else
endText = mw.ustring.gsub(endText, '(%(%d+%s*–%s*%d+)%s
endText = mw.ustring.gsub(endText, '%([Aa]%.?[Ee]%.?[Tt]%.?%)', '([[Overtime (sports)#Association football|a.e.t.]])')
end
Line 375 ⟶ 401:
local function cleanTeam(str, defaultName)
if str and str ~= "" then
str = str:gsub("</?%w+[^>]*>", "")
str = str:gsub('\127%\'"`UNIQ.-QINU`"%\'\127', '')
Line 407 ⟶ 433:
link = "[[#" .. team1 .. " v " .. team2 .. "|" .. linkScore .. "]]"
end
return link .. score:sub(#linkScore + 1)
end
Line 415 ⟶ 442:
-- Function to process notes for aggregate and leg scores
local function processNote(frame, notes, noteKey, noteText, endText, rowIndex, rand_val, noteGroup, baselink, currentPageTitle)
if not noteText then return endText, notes end
if noteText:match("^%s*<sup") or noteText:match("^\127%\'%\"`UNIQ") then
Line 436 ⟶ 463:
local referenced_note_id = '"table_note_' .. referenced_note .. '_' .. rand_val .. '"'
return endText .. createInlineNote(referenced_note_id), notes
end
-- Process anchor links in noteText before storing
if noteText:find("%[%[") then
noteText = rewriteAnchorLinks(noteText, baselink, currentPageTitle)
end
Line 727 ⟶ 759:
local aggSpan = (disableNoWrap or (not noWrap and not disableNoWrap and aggParen))
aggregateScore, aggregateEndText = format_and_extract_score(aggregateScore, aggSpan)
-- Apply link rewriting to note text before creating the note
aggregateEndText, notes = processNote(frame, notes, 'agg', aggNote, aggregateEndText, rowIndex, rand_val, noteGroup, baselink, currentPageTitle)
if generateLinks and legs == 0 then
-- Skip link generation for "Bye" entries
aggregateScore = cleanAndGenerateLinks(team1, team2, aggregateScore, false)▼
local isBye = aggregateScore:match("^%s*[Bb][Yy][Ee]%s*$") or aggregateScore:match("|[Bb][Yy][Ee]%]%]")
if not isBye then
▲ aggregateScore = cleanAndGenerateLinks(team1, team2, aggregateScore, false)
end
end
Line 752 ⟶ 789:
-- When set by user, adds blank flag placeholder next to team names
if fillBlanks and showFlags then
if not team1Icon or team1Icon == "" then
team1Text = team1Text .. ' ' .. placeholderFlag
Line 814 ⟶ 851:
local legSpan = (disableNoWrap or (not noWrap and not disableNoWrap and legParen))
legScore, legEndText = format_and_extract_score(legScore, legSpan)
legEndText, notes = processNote(frame, notes, 'leg' .. leg, legNote, legEndText, rowIndex, rand_val, noteGroup, baselink, currentPageTitle)
if generateLinks and not aggregateContent:lower():find("bye") then
if leg == 1 then
Line 851 ⟶ 889:
local tableCode = tostring(root)
-- Rewrite anchor links for the entire table (except for notes which were handled separately)
tableCode = rewriteAnchorLinks(tableCode, baselink, currentPageTitle)
▲ if baselink ~= '' then
▲ tableCode = mw.ustring.gsub(tableCode, '(%[%[)(#[^%[%]]*%|)', '%1' .. baselink .. '%2')
▲ end
▲ local escapedTitle = currentPageTitle:gsub("([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1")
▲ local titlePattern = '%[%[' .. escapedTitle .. '(#[^%[%]]*%|)'
▲ tableCode = mw.ustring.gsub(tableCode, titlePattern, '[[%1')
-- Return the completed table with rewritten links
return tableCode
end
|