Wikipedia : Escape Brackets inside of Link

Learn wikipedia : escape brackets inside of link with practical examples, diagrams, and best practices. Covers wikipedia development techniques with visual explanations.

Escaping Brackets in Wikipedia Links: A Comprehensive Guide

Hero image for Wikipedia : Escape Brackets inside of Link

Learn how to correctly format Wikipedia links that contain square brackets within the link text or URL, ensuring proper rendering and functionality.

When editing Wikipedia, creating internal or external links is a fundamental task. However, a common challenge arises when the desired link text or the URL itself contains square brackets []. These brackets are special characters in Wikipedia's wikitext syntax, used to define links. If not handled correctly, they can break the link, lead to malformed text, or cause unexpected rendering issues. This article will guide you through the proper methods to escape or handle brackets within Wikipedia links, ensuring your contributions are accurate and well-formatted.

Understanding the Problem: Why Brackets Cause Issues

Wikipedia's wikitext uses double square brackets [[...]] for internal links and single square brackets [...] for external links. The content within these brackets is parsed specifically to identify the target page/URL and the display text. When an additional square bracket appears inside this structure, the parser can become confused, interpreting it as the end of the link or the beginning of a new, unintended wikitext element. This often results in broken links, visible raw wikitext, or incorrect formatting.

flowchart TD
    A[User writes wikitext] --> B{Contains brackets in link?}
    B -- No --> C[Link renders correctly]
    B -- Yes --> D{Are brackets escaped?}
    D -- No --> E[Parsing Error/Broken Link]
    D -- Yes --> C

Flowchart illustrating how brackets affect Wikipedia link parsing.

The most common and recommended way to include square brackets within the display text of a Wikipedia link is to use HTML entities. Instead of typing [ or ], you use their corresponding HTML entity codes: [ for [ and ] for ]. The Wikipedia parser will interpret these entities as literal brackets, displaying them correctly without interfering with the link's wikitext syntax.

'''Internal Link Example:'''
[[Article Name|Display text with [brackets]]]

'''External Link Example:'''
[http://example.com Display text with [brackets]]

Using HTML entities for brackets in link display text.

When square brackets are part of the actual URL in an external link, using HTML entities in the URL itself will not work, as URLs require percent-encoding for special characters. For external links [URL display text], if the URL contains [ or ], you must percent-encode them. The percent-encoded values are %5B for [ and %5D for ]. Most browsers and URL encoders handle this automatically, but it's crucial to be aware of it if you're constructing URLs manually.

'''Original URL with brackets:'''
`http://example.com/search?query=[term]`

'''Correctly encoded URL for Wikipedia:'''
`[http://example.com/search?query=%5Bterm%5D Search for [term]]`

Percent-encoding brackets within an external link URL.

The <nowiki> tag tells the Wikipedia parser to ignore any wikitext formatting within its boundaries. While not ideal for active links, it can be useful if you need to display raw wikitext that looks like a link but should not be parsed as one, and contains brackets. For example, if you are demonstrating how to write a link that includes brackets, but the example itself shouldn't be a live link.

<nowiki>[[Article Name|Display text with [brackets]]] </nowiki>

'''Result:''' [[Article Name|Display text with [brackets]]]

Using <nowiki> to display raw wikitext with brackets without parsing.

Follow these steps to correctly incorporate brackets into your Wikipedia links:

1. Identify Bracket Location

Determine if the bracket is intended for the visible link text or if it's part of the actual URL.

2. For Brackets in Display Text

Replace [ with &#91; and ] with &#93;. For example, [[Target|My &#91;Special&#93; Link]].

Ensure the URL is percent-encoded. If you're copying a URL from a browser, it's usually already encoded. If constructing manually, replace [ with %5B and ] with %5D. For example, [http://example.com/query?q=%5Btest%5D Search Test].

4. Review and Preview

Always use the 'Show preview' button on Wikipedia to verify that your link renders as intended before saving your changes.