Escape | (vertical bar/pipe) in URL in Wiki Markup Template

10.7k views Asked by At

Is it possible to escape and keep the nonstandard | character as is in an URL in a template Wiki Markup within a table?

{| class="wikitable"
|-
! Test in Table
|-
| [http://example.org/{var1}|{var2}|{var3} Example]
|}

Should render something like this in the table cell

[http://example.org/1|2|3 Example]

and link to

http://example.org/1|2|3

with the vertical bars as is and not encoded like this

http://example.org/1%7C2%7C3

The 3rd party website requires «|» in the URL, I would fix the URL handling on the server side but that is out of my hands for now. Any help on a workaround?

I tried these:

[http://example.org/1|2|3 Example] doesn't work within a table   
[http://example.org/{var1}|{var2}|{var3} Example] works in tables

but both create valid standard URLs where the vertical bar is properly URL encoded as %7C like above which I would like to prevent.

2

There are 2 answers

1
BenMQ On BEST ANSWER

External links, without support from additional extensions, can only be produced by the [url description] syntax or a plain URL itself. Although as mentioned by skalee, you can use {{!}} or other methods to prevent the pipe symbol from being interpreted as part of the Wikitext syntax, the final link will always be encoded.

Without help from extensions, a quick solution would be JavaScript. (If it is on your own MediaWiki site, that would be very simple. MediaWiki:Common.js contains JavaScript that will be loaded for all users).

0
baptx On

In addition to the syntax {{!}} previously mentioned, it is also possible to escape the vertical bar / pipe using {{pipe}} or using <nowiki>text containing the character | (pipe)</nowiki>. Using the HTML entity &#124; also works.

Source:

https://en.wikipedia.org/wiki/Template:Cite_web#Title

https://en.wikipedia.org/wiki/Help:Table#Rendering_pipe_itself