Search code examples
githubwiki

Linking to a page with a dash (hyphen) in the title In GitHub wiki


In GitHub wiki, is there any easy way to link to a page which has a dash in the title?

I'm adding reference pages to the GitHub wiki for a PowerShell module I wrote. The function names in the module follow PowerShell naming conventions so all have dashes (hyphens) in their names, similar to Set-LogConfiguration.

I want to create a man page in the GitHub wiki for each function. I can create pages with titles like "Set-LogConfiguration" without problem. However, I cannot create internal links to these pages.

I've tried the following:

[[Set-LogConfiguration]]
[[Set\-LogConfiguration]]
[[Set LogConfiguration]]
[[Set%2DLogConfiguration]]

None of these work. In each case GitHub wiki indicates the page being linked to doesn't exist.

When I save a page with a link like

[[Set-LogConfiguration]]

and then follow the link, it brings up the "Create new page" screen, to create a page Set LogConfiguration (notice the space, rather than a dash, between "Set" and "LogConfiguration"). The URL will be

https://github.com/<my repo>/wiki/Set-LogConfiguration

If I create the page directly, with title "Set-LogConfiguration", it appears to create a page with the same URL as the one created from the link, but they are two different pages.


Solution

  • After much experimenting, I've figured out how to link to a page with a dash (hyphen) in the title:

    Step Action Notes
    1 Create the page with the dash in the title directly, by clicking the "New page" button. Do NOT create the page by adding a link on another page, then clicking that link to create the page. This would create the page without the dash in the title. For example, following a link [[Set-LogConfiguration]] would create a page with a URL https://github.com/<my repo>/wiki/Set-LogConfiguration but the page title would be Set LogConfiguration, without the dash.
    2 Once you've created the page you want to link to, go to the address bar of your browser and copy the page title out of the URL.

    For example, if the URL is https://github.com/<my repo>/wiki/Set‐LogConfiguration, copy the Set‐LogConfiguration portion of the URL.

    It appears GitHub wiki replaces the dash in the page title with the hex values E2 80 90 in the URL, although these will render as a dash in the browser address bar (sneaky!). Copying the page title out of the address bar will pick up the hex characters.

    3 Edit the page you want to add the link to. Where you want to add the link, paste the page title copied from the URL, then surround it with double square brackets, similar to [[page_title_copied_from_the_URL]].

    In the example above, the link will be [[Set‐LogConfiguration]].

    Do NOT type the page title in by hand. Paste the page title copied from the URL. In your browser the text you paste will appear to be normal text, including the dash in the page title. However, in reality it will include those three hex values.

    The above process doesn't take too long and will give you a page that has a dash in the title and a link to that page that works.

    The only problem is that anyone subsequently editing the page with the link on it won't realise the link contains special characters, since it looks like a normal dash (hyphen). It would easy for someone to break the link by editing it, replacing the special characters that look like a dash with a real dash.