Module:Random slideshow/sandbox: Difference between revisions

Content deleted Content added
Fully turn all {{!}} into | now that tag is processed using functions rather than preprocessed text that needs escaping
improve alt param position check by temporarily removing pipes in wikilinks during processing
Line 40:
local sortedLines = nonRandom and galleryLines or randomModule.main('array', randomiseArgs)
for i = 1, #sortedLines do
sortedLines[i]local currentLine = sortedLines[i]:gsub(
-- move the alt parameter to the end of the file should it exist to fix linter errors
-- disable pipes in wikilinks
-- make sure the parameter isnt perhaps being confused by a wikilink inside it
local altParamcurrentLine = sortedLines[i]currentLine:gsub(
"%[%[(.-)|(.-)]]",
"[[%1__PIPE__%2]]")
-- move theany alt parameter to the end ofto avoid putting the fileswitcher shouldin ittoo existearly toand causing fixa linter errorserror
currentLine = currentLine:gsub(
"^(.+)(|alt=[^|]*)(.*)$",
"%1%3%2")
-- bring back pipes in wikilinks
if not string.find(altParam,"%[%[") then
sortedLines[i]currentLine = sortedLines[i]currentLine:gsub(
"^%[%[(.+)(|alt=[^|]*-)__PIPE__(.*-)$]]",
"[[%1%3|%2]]")
-- insert a switcher-label span just after the first pipe, which should ideally be the caption
end
currentLine = currentLine:gsub(
-- insert a switcher-label span just after the first pipe
sortedLines[i] = sortedLines[i]:gsub(
"|",
'|<span class="switcher-label" style="display:none"><span class="randomSlideshow-sr-only">Image ' .. tostring(i) .. '</span></span>',
1)
mw.log("Workin with",sortedLines[i]) = currentLine
end
local galleryContent = table.concat(sortedLines, '\n')