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

Invalid link references in reStructuredText #511

Closed
roxeteer opened this issue May 14, 2012 · 6 comments
Closed

Invalid link references in reStructuredText #511

roxeteer opened this issue May 14, 2012 · 6 comments
Labels

Comments

@roxeteer
Copy link

If multiple links have the same clickable text, the generated references are incorrect in reStructuredText. For example:

This Markdown sample:

[click here](http://www.example.com/) or [click here](http://johnmacfarlane.net/pandoc/)

generates this reST code:

`click here`_ or `click here`_

.. _click here: http://www.example.com/
.. _click here: http://johnmacfarlane.net/pandoc/

which fails in Sphinx reST parser and in Pandoc produces this incorrect HTML:

<p><a href="http://johnmacfarlane.net/pandoc/">click here</a> or <a href="http://johnmacfarlane.net/pandoc/">click here</a></p>

The solution would be that Pandoc either generates code with embedded URIs or uses indirect hyperlink targets:

`click here <http://www.example.com/>`_ or `click here <http://johnmacfarlane.net/pandoc/>`_

or

`click here`__ or `click here`__

.. _link1: http://www.example.com/
.. _link2: http://johnmacfarlane.net/pandoc/

__ link1_
__ link2_
@roxeteer
Copy link
Author

Related to this issue, Pandoc is not able to correctly parse indirect hyperlink targets (the last example): #512

@cjerdonek
Copy link

I think I came across this same issue with duplicate text.

The reStructuredText output from pandoc generated the following warning when I passed the pandoc output to Python's Docutils (specifically rst2html.py) for conversion to HTML:

<stdin>:6: (WARNING/2) Duplicate explicit target name: "github".

Another option would be for pandoc to issue a warning in this case.

@jgm
Copy link
Owner

jgm commented Oct 3, 2012

Note: by default pandoc will produce the output you desire,

`click here <http://www.example.com/>`_ or `click here <http://johnmacfarlane.net/pandoc/>`_

It only produces reference-style links if you use the --reference-links option.

I'm guessing, though, that you want reference style links in general; you just want pandoc to be intelligent enough not to use them when it will produce problems.

@cjerdonek
Copy link

This issue discusses two closely related issues: outputting reference-style links with duplicate reference names (the original issue that produces incorrect HTML) and outputting embedded URIs (pandoc's default behavior) with duplicate reference names (the behavior I reported that yields a warning when the output is passed to rst2html.py).

I think the solution in both cases is to use anonymous references, which @roxeteer described partially in the original post and which are discussed here in more detail:

As described in the links above, anonymous references can be achieved by using a double underscore instead of a single underscore in both cases. In the case of embedded URI's (non-reference-style links), this would mean doing this--

`click here <http://www.example.com/>`__

instead of this--

`click here <http://www.example.com/>`_

@jgm
Copy link
Owner

jgm commented Jan 14, 2013

@cjerdonek, thanks. I should have a fix soon.

@jgm jgm closed this as completed in 45895b5 Jan 14, 2013
@cjerdonek
Copy link

Awesome, thanks again! 😀

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

No branches or pull requests

3 participants