SF.net SVN: docutils:[10211] trunk/docutils
milde--- via Docutils-checkins <[email protected]> Tue, 19 Aug 2025 20:28:48 +0000
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 10211
http://sourceforge.net/p/docutils/code/10211
Author: milde
Date: 2025-08-19 20:28:48 +0000 (Tue, 19 Aug 2025)
Log Message:
-----------
Better error reports for hyperlinks with embedded URI or alias.
Check and report for common typos when an undefined referencname
contains a `<` or `>`.
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/docutils/transforms/references.py
trunk/docutils/test/test_transforms/test_hyperlinks.py
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2025-08-19 18:38:11 UTC (rev 10210)
+++ trunk/docutils/HISTORY.rst 2025-08-19 20:28:48 UTC (rev 10211)
@@ -35,9 +35,13 @@
- Better error messages for grid table markup errors (bug #504),
based on patch #214 by Jynn Nelson.
-__ RELEASE-NOTES.html#nested-parsing
+ __ RELEASE-NOTES.html#nested-parsing
+* docutils/transforms/references.py
+ - Better error reports for hyperlinks with embedded URI or alias.
+
+
Release 0.22 (2026-07-29)
=========================
Modified: trunk/docutils/docutils/transforms/references.py
===================================================================
--- trunk/docutils/docutils/transforms/references.py 2025-08-19 18:38:11 UTC (rev 10210)
+++ trunk/docutils/docutils/transforms/references.py 2025-08-19 20:28:48 UTC (rev 10211)
@@ -955,11 +955,29 @@
if refname in self.document.nameids:
msg = self.document.reporter.error(
'Duplicate target name, cannot be used as a unique '
- 'reference: "%s".' % (node['refname']), base_node=node)
+ f'reference: "{refname}".', base_node=node)
else:
+ if '<' in refname or '>' in refname:
+ hint = 'Did you want to embed a URI or alias?'
+ if '<' not in refname:
+ hint += '\nOpening bracket missing.'
+ elif ' <' not in refname:
+ hint += ('\nThe embedded reference must be preceded'
+ ' by whitespace.')
+ if '>' not in refname:
+ hint += '\nClosing bracket missing.'
+ elif not refname.endswith('>'):
+ hint += ('\nThe embedded reference must be the last text'
+ ' before the end string.')
+ if '< ' in refname or ' >' in refname:
+ hint += ('\nWhitespace around the embedded reference'
+ ' is not allowed.')
+ details = [nodes.paragraph('', hint)]
+ else:
+ details = []
msg = self.document.reporter.error(
- f'Unknown target name: "{node["refname"]}".',
- base_node=node)
+ f'Unknown target name: "{refname}".',
+ *details, base_node=node)
msgid = self.document.set_id(msg)
prb = nodes.problematic(node.rawsource, node.rawsource, refid=msgid)
try:
Modified: trunk/docutils/test/test_transforms/test_hyperlinks.py
===================================================================
--- trunk/docutils/test/test_transforms/test_hyperlinks.py 2025-08-19 18:38:11 UTC (rev 10210)
+++ trunk/docutils/test/test_transforms/test_hyperlinks.py 2025-08-19 20:28:48 UTC (rev 10211)
@@ -432,6 +432,91 @@
.
"""],
["""\
+`link <address >`_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <problematic ids="problematic-1" refid="system-message-1">
+ `link <address >`_
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "link <address >".
+ <paragraph>
+ Did you want to embed a URI or alias?
+ Whitespace around the embedded reference is not allowed.
+"""],
+["""\
+`link < address>`_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <problematic ids="problematic-1" refid="system-message-1">
+ `link < address>`_
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "link < address>".
+ <paragraph>
+ Did you want to embed a URI or alias?
+ Whitespace around the embedded reference is not allowed.
+"""],
+["""\
+`link <address> e`_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <problematic ids="problematic-1" refid="system-message-1">
+ `link <address> e`_
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "link <address> e".
+ <paragraph>
+ Did you want to embed a URI or alias?
+ The embedded reference must be the last text before the end string.
+"""],
+["""\
+`link<address>`_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <problematic ids="problematic-1" refid="system-message-1">
+ `link<address>`_
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "link<address>".
+ <paragraph>
+ Did you want to embed a URI or alias?
+ The embedded reference must be preceded by whitespace.
+"""],
+["""\
+`link <address`_
+`link address>`_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <problematic ids="problematic-1" refid="system-message-1">
+ `link <address`_
+ \n\
+ <problematic ids="problematic-2" refid="system-message-2">
+ `link address>`_
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "link <address".
+ <paragraph>
+ Did you want to embed a URI or alias?
+ Closing bracket missing.
+ <system_message backrefs="problematic-2" ids="system-message-2" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "link address>".
+ <paragraph>
+ Did you want to embed a URI or alias?
+ Opening bracket missing.
+"""],
+["""\
Hyperlinks with angle-bracketed text need escaping.
See `Element \\<a>`_, `Element <b\\>`_, and `Element <c>\\ `_.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.