Module:Addlink

From The Sims Wiki, a collaborative database for The Sims series
Jump to navigation Jump to search

This module's documentation page can be edited at Module:Addlink/doc.


This module sanitizies link input. It will add [[ ]] around text given to it, but will ignore it if it sees that square brackets are already present.

Examples

{{#invoke:Addlink|wrapInLink|[[Foo]]}}
{{#invoke:Addlink|wrapInLink|Foo}}

Both produce the following output:

Foo

Piped links also work.

{{#invoke:Addlink|wrapInLink|[[Foo|Bar]]}}
{{#invoke:Addlink|wrapInLink|Foo{{!}}Bar}}

Both produce:

Bar

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.getTargetFromText(frame)
    local text = frame.args[1]
    return string.match(frame, "^%[%[")
    end

function p.wrapInLink(frame)
	local args = getArgs(frame)
    local text = args[1]
  if(string.match(text, "^%[%[") ~= nil) then
    return text
  end

  return '[[' .. text .. ']]'
end

return p