|
From: <mi...@us...> - 2013-03-11 21:01:10
|
Revision: 7629
http://docutils.svn.sourceforge.net/docutils/?rev=7629&view=rev
Author: milde
Date: 2013-03-11 21:01:03 +0000 (Mon, 11 Mar 2013)
Log Message:
-----------
Treat embedded standalone hyperlinks as URI, even if ending in underscore.
Modified Paths:
--------------
trunk/docutils/docs/ref/rst/restructuredtext.txt
trunk/docutils/docutils/parsers/rst/states.py
trunk/docutils/test/test_transforms/test_hyperlinks.py
Modified: trunk/docutils/docs/ref/rst/restructuredtext.txt
===================================================================
--- trunk/docutils/docs/ref/rst/restructuredtext.txt 2013-03-09 10:19:35 UTC (rev 7628)
+++ trunk/docutils/docs/ref/rst/restructuredtext.txt 2013-03-11 21:01:03 UTC (rev 7629)
@@ -2656,8 +2656,9 @@
Embedded URIs and Aliases
`````````````````````````
-A hyperlink reference may directly embed a target URI or a hyperlink
-reference within angle brackets ("<...>") as follows::
+A hyperlink reference may directly embed a target URI or (since
+Docutils 0.11) a hyperlink reference within angle brackets ("<...>")
+as follows::
See the `Python home page <http://www.python.org>`_ for info.
@@ -2692,20 +2693,26 @@
__ http://www.rfc-editor.org/rfc/rfc2396.txt
__ http://www.rfc-editor.org/rfc/rfc2732.txt
-If a target URI happens to end with an underscore, this needs to be
-backslash-escaped to avoid being parsed as hyperlink reference. For
-example ::
+`Standalone hyperlinks`_ are treated as URIs, even if they end with an
+underscore like in the example of a Python function documentation::
+ `__init__ <http:example.py.html#__init__>`__
+
+If a target URI that is not recognized as `standalone hyperlink`_ happens
+to end with an underscore, this needs to be backslash-escaped to avoid
+being parsed as hyperlink reference. For example ::
+
Use the `source <parrots.txt\_>`__.
creates an anonymous reference to the file ``parrots.txt_``.
If the reference text happens to end with angle-bracketed text that is
-*not* a URI or hyperlink reference, the open-angle-bracket needs to be
-backslash-escaped. For example, here is a reference to a title
-describing a tag::
+*not* a URI or hyperlink reference, at least one angle-bracket needs to
+be backslash-escaped or an escaped space should follow. For example, here
+are three references to titles describing a tag::
- See `HTML Element: \<a>`_ below.
+ See `HTML Element: \<a>`_, `HTML Element: <b\> `_, and
+ `HTML Element: <c>\ `_.
The reference text may also be omitted, in which case the URI will be
duplicated for use as the reference text. This is useful for relative
@@ -2820,6 +2827,7 @@
addition to being replaced, the replacement text or element will
refer to the "substitution and hyperlink reference" target.
+.. _standalone hyperlink:
Standalone Hyperlinks
---------------------
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2013-03-09 10:19:35 UTC (rev 7628)
+++ trunk/docutils/docutils/parsers/rst/states.py 2013-03-11 21:01:03 UTC (rev 7629)
@@ -792,7 +792,8 @@
if match: # embedded <URI> or <alias_>
text = unescape(escaped[:match.start(0)])
aliastext = unescape(match.group(2), restore_backslashes=True)
- if aliastext.endswith('_') and not aliastext.endswith(r'\_'):
+ if aliastext.endswith('_') and not (aliastext.endswith(r'\_')
+ or self.patterns.uri.match(aliastext)):
aliastype = 'name'
alias = normalize_name(aliastext[:-1])
target = nodes.target(match.group(1), refname=alias)
Modified: trunk/docutils/test/test_transforms/test_hyperlinks.py
===================================================================
--- trunk/docutils/test/test_transforms/test_hyperlinks.py 2013-03-09 10:19:35 UTC (rev 7628)
+++ trunk/docutils/test/test_transforms/test_hyperlinks.py 2013-03-11 21:01:03 UTC (rev 7629)
@@ -374,7 +374,6 @@
.
<target ids="redirect" names="redirect" refuri="spam.py">
"""],
-# TODO: suppress the INFO message?
["""\
An `embedded alias <alias_>`_ with unknown reference.
""",
@@ -397,6 +396,46 @@
Hyperlink target "embedded alias" is not referenced.\
"""],
["""\
+An embedded URI with trailing underline:
+`__init__ <http:example.py.html#__init__>`__.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ An embedded URI with trailing underline:
+ <reference name="__init__" refuri="http:example.py.html#__init__">
+ __init__
+ .
+"""],
+["""\
+Hyperlinks with angle-bracketed text need escaping.
+
+See `Element \<a>`_, `Element <b\>`_, and `Element <c>\ `_.
+
+.. _`Element <a>`:
+.. _`Element <b>`:
+.. _`Element <c>`: elements.txt
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Hyperlinks with angle-bracketed text need escaping.
+ <paragraph>
+ See \n\
+ <reference name="Element <a>" refuri="elements.txt">
+ Element <a>
+ , \n\
+ <reference name="Element <b>" refuri="elements.txt">
+ Element <b>
+ , and \n\
+ <reference name="Element <c>" refuri="elements.txt">
+ Element <c>
+ .
+ <target refid="element-a">
+ <target refid="element-b">
+ <target ids="element-c element-b element-a" names="element\ <c> element\ <b> element\ <a>" refuri="elements.txt">
+"""],
+["""\
.. _target:
.. [1] Footnote; target_
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|