Module:LinkUtil: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 5: Line 5:
     -- don't return second values
     -- don't return second values
     local ret = str:gsub('_', ' '):gsub('%s*%(.*%)','')
     local ret = str:gsub('_', ' '):gsub('%s*%(.*%)','')
    return ret
end
function p.getDab(str)
    local ret = str:gsub('_', ' '):gsub('.*%s*%(',''):gsub('%s*%).*','')
     return ret
     return ret
end
end
Line 25: Line 30:
function p.addPipedLink(page)
function p.addPipedLink(page)
local ret = '[[' .. page .. '|]]'  
local ret = '[[' .. page .. '|]]'  
return ret
end
function p.stripLink(page)
local ret = page:gsub('_', ' '):gsub('%s*%[%[',''):gsub('%s*%]%]','')
    return ret
end
function p.getLinkText(page)
local ret = page:gsub('_', ' '):gsub('%s*%[%[:?',''):gsub('%|.*',''):gsub('%s*%]%]','')
if ret:sub(1,1) == ":" then
ret = ret:sub(2)
end
return ret
end
function p.getDisplayText(page)
local ret = page:gsub('_', ' '):gsub('%s*%[%[',''):gsub('.*%|',''):gsub('%s*%]%]','')
if ret:sub(1,1) == ":" then
ret = ret:sub(2)
end
return ret
return ret
end
end


return p
return p

Latest revision as of 20:16, 1 July 2023

Documentation for this module may be created at Module:LinkUtil/doc

local p = {} --p stands for package

-- from https://lol.fandom.com/wiki/Module:EsportsUtil
function p.stripDab(str)
    -- don't return second values
    local ret = str:gsub('_', ' '):gsub('%s*%(.*%)','')
    return ret
end

function p.getDab(str)
    local ret = str:gsub('_', ' '):gsub('.*%s*%(',''):gsub('%s*%).*','')
    return ret
end

function p.stripPipe(str)
    local ret = str:gsub('%|.*','')
    return ret
end

function p.addLink(page, display)
	local ret = '[[' .. page
	if display then
		 ret = ret .. '|' .. display .. ']]'
	else
		ret = ret .. ']]'
	end
	return ret
end

function p.addPipedLink(page)
	local ret = '[[' .. page .. '|]]' 
	return ret
end

function p.stripLink(page)
	local ret = page:gsub('_', ' '):gsub('%s*%[%[',''):gsub('%s*%]%]','')
    return ret	
end

function p.getLinkText(page)
	local ret = page:gsub('_', ' '):gsub('%s*%[%[:?',''):gsub('%|.*',''):gsub('%s*%]%]','')
	if ret:sub(1,1) == ":" then
		ret = ret:sub(2)
	end
	return ret
end

function p.getDisplayText(page)
	local ret = page:gsub('_', ' '):gsub('%s*%[%[',''):gsub('.*%|',''):gsub('%s*%]%]','')
	if ret:sub(1,1) == ":" then
		ret = ret:sub(2)
	end
	return ret
end

return p