Module:Consecutive links: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 11: Line 11:
local linkprefix = args[6]
local linkprefix = args[6]
local linkpostfix = args[7]
local linkpostfix = args[7]
local brackets = brackets or {'[[', ']]'}
local brackets = brackets or {'[[', ']]', ''}


local b = string.gsub(args[1], "%s*" .. separator .. "%s*", linkpostfix .. brackets[2] .. replacer .. brackets[1] .. linkprefix)
local b = string.gsub(args[1], "%s*" .. separator .. "%s*", linkpostfix .. brackets[2] .. replacer .. brackets[1] .. linkprefix.. brackets[3])
return prefix .. brackets[1] .. linkprefix .. b .. linkpostfix ..brackets[2] .. postfix
return prefix .. brackets[1] .. linkprefix.. brackets[3] .. b .. linkpostfix ..brackets[2] .. postfix
end
end


function p.consecutivelinks(frame)
function p.consecutivelinks(frame)
return p.parse(frame.args, {'[[', ']]'})
return p.parse(frame.args, {'[[', ']]', ''})
end
end


function p.consecutivetemplates(frame)
function p.consecutivetemplates(frame)
return p.parse(frame.args, {'{{', '}}'})
return p.parse(frame.args, {'{{', '}}', '|'})
end
end


return p
return p

Revision as of 17:10, 16 November 2019


local p = {}

function p.parse(args, brackets)
if args.args ~= nil then
  args = args.args
end
local separator = args[2]
local replacer = args[3]
local prefix = args[4]
local postfix = args[5]
local linkprefix = args[6]
local linkpostfix = args[7]
local brackets = brackets or {'[[', ']]', ''}

local b = string.gsub(args[1], "%s*" .. separator .. "%s*", linkpostfix .. brackets[2] .. replacer .. brackets[1] .. linkprefix.. brackets[3])
return prefix .. brackets[1] .. linkprefix.. brackets[3] .. b .. linkpostfix ..brackets[2] .. postfix
end

function p.consecutivelinks(frame)
return p.parse(frame.args, {'[[', ']]', ''})
end

function p.consecutivetemplates(frame)
return p.parse(frame.args, {'{{', '}}', '|'})
end

return p