Template:Wikilink
Documentation for Wikilink
. This is a template that can check whether a given input is a wiki link, and extract the link / text from that link.
A wiki link is defined as a link that is inserted using [...] for internal links or [[...]] for external links.
The template takes 1 required parameter (the input string), and 1 optional parameter. The optional parameter can be one of link (returns the link portion, if applicable) or text (returns the text portion, if applicable).
The template can be used with #if to check if the input is an internal wiki link (returns 1), external wiki link (returns 2), or neither (returns nothing).
This template probably doesn't work for all variants of wiki links - although it does work with the Pipe Trick.
For an overview, see the examples/test cases table below:
input | renders as | output | {{#if:...|true|false}}-test |
---|---|---|---|
gibberish | gibberish | false | |
gibberish|link | false | ||
gibberish|text | false | ||
[[internal link]] | internal link | 1 | true |
[[internal link]]|link | internal link | true | |
[[internal link]]|text | false | ||
[[internal link|some text]] | some text | 1 | true |
[[internal link|some text]]|link | internal link | true | |
[[internal link|some text]]|text | some text | true | |
[[internal link|some text]]overflow | some textoverflow | 1 | true |
[[internal link|some text]]overflow|link | internal link | true | |
[[internal link|some text]]overflow|text | some textoverflow | true | |
[http://www.example.com/] | [1] | 2 | true |
[http://www.example.com/]|link | http://www.example.com/ | true | |
[http://www.example.com/]|text | false | ||
[http://www.example.com/ some text] | some text | 2 | true |
[http://www.example.com/ some text]|link | http://www.example.com/ | true | |
[http://www.example.com/ some text]|text | some text | true | |
[[Help:Pipe Trick|]] | Pipe Trick | 1 | true |
[[Help:Pipe Trick|]]|link | Help:Pipe Trick | true | |
[[Help:Pipe Trick|]]|text | Pipe Trick | true | |
[[pipe (computing)|]]mill | pipemill | 1 | true |
[[pipe (computing)|]]mill|link | pipe (computing) | true | |
[[pipe (computing)|]]mill|text | pipemill | true |