Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape colons in relative links e.g. MediaWiki category links #2849

Open
peterjc opened this issue Apr 10, 2016 · 2 comments
Open

Escape colons in relative links e.g. MediaWiki category links #2849

peterjc opened this issue Apr 10, 2016 · 2 comments

Comments

@peterjc
Copy link

peterjc commented Apr 10, 2016

Referring to https://www.mediawiki.org/wiki/Help:Categories in mediawiki,

  • [[Category:Name]] --> part of category "Name" (used in some outputs from pandoc)
  • [[Category:Name|Sort]] --> part of category "Name" using sort key "Sort" in place of page title
  • [[:Category:Help]] --> link with text "Category:Help"
  • [[:Category:Help|Help category]] link with text "Help category"

Try converting this to RST using pandoc v1.17.0.2 (Mac OS X),

$ echo "This page is in [[Category:Example]] and here is a link to the [[:Category:Help|Help category]], and an [http://example.org external site] too." | pandoc -f mediawiki -t rst
This page is in and here is a link to the `Help
category <:Category:Help>`__, and an `external
site <http://example.org>`__ too.

Or, to HTML,

$ echo "This page is in [[Category:Example]] and here is a link to the [[:Category:Help|Help category]], and an [http://example.org external site] too." | pandoc -f mediawiki -t html
<p>This page is in and here is a link to the <a href=":Category:Help" title="wikilink">Help category</a>, and an <a href="http://example.org">external site</a> too.</p>
<p><a href="Category:Example" class="uri" title="wikilink">Category:Example</a></p>

The unsupported tag [[Category:Example]] is dropped here (fine - see comment below using markdown output). The external link to http://example.org is perfect.

The bug is the URL used for the "Help Category". This is Category:Example in HTML which breaks (see below), but :Category:Example in the RST which is worse - notice Mediawiki's special syntax leading colon is still there.

Due to the special URL scheme notation, this URL should be presented as Category%3AExample where the colon is %3A, as otherwise the browser seems to interpret this as a (undefined) URL scheme (like http://example.org or https://example.org or here category:...).

@peterjc
Copy link
Author

peterjc commented Apr 10, 2016

Pandoc does handle the category tag in markdown output, e.g.

$ echo "This page is in [[Category:Example]] and here is a link to the [[:Category:Help|Help category]], and an [http://example.org external site] too." | pandoc -f mediawiki -t markdown_github-hard_line_breaks
This page is in and here is a link to the [Help
category](:Category:Help "wikilink"), and an [external
site](http://example.org) too.

<Category:Example>

As an aside, clearly my example should not really have put the MediaWiki [[Category:Example]] mid sentence.

Note that the same URL problem is shown here too.

peterjc added a commit to peterjc/mediawiki_to_git_md that referenced this issue Apr 10, 2016
Attempts to side-step jgm/pandoc#2849
as part of resolving issue #6.
@peterjc
Copy link
Author

peterjc commented Apr 15, 2016

There is an overlapping/related issue with linking to user pages, and any other MediaWiki special pages with a colon in their name, e.g.

$ echo "This was written by [[User:pjc|Peter]]." | pandoc -f mediawiki -t markdown_github-hard_line_breaks
This was written by [Peter](User:pjc "wikilink").

In order to prevent the browser trying to interpret this as a URL scheme user:, it seems simplest to escape the colon in the URL:

This was written by [Peter](User%3Apjc "wikilink").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants