Module:Addlink

From The Sims Wiki, a collaborative database for The Sims series
This is the current revision of this page, as edited by K6ka (talk | contribs) at 19:58, 30 April 2019 (K6ka moved page Module:InfoboxLink to Module:Addlink without leaving a redirect: Consistency w/ {{Delink}}). The present address (URL) is a permanent link to this version.
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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