|
From: <mi...@us...> - 2026-07-14 13:32:08
|
Revision: 10382
http://sourceforge.net/p/docutils/code/10382
Author: milde
Date: 2026-07-14 13:32:05 +0000 (Tue, 14 Jul 2026)
Log Message:
-----------
"lazy IDs": Don't generate IDs for external and indirect targets.
External and indirect targets have a "refuri", "refname" or "refid"
attribute that is transferred to all references to this target
(by the `IndirectHyperlinks` transform for named targets and by the
`AnonymousHyperlinks` transform for anonymouns targets).
The target's ID is not required and not shown in the output.
The change keeps the "identifier" namespace clean.
Example: The reference names "topic" and "<topic>" both map to the ID "topic".
With "legacy_ids", the section title in the following sample
would get the ID "topic-1":
~~~
.. _<topic>: ../doctree.html#topic
Topic
=====
:Doctree Element: `\<topic>`_
~~~
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/RELEASE-NOTES.rst
trunk/docutils/docs/ref/rst/directives.rst
trunk/docutils/docs/user/config.rst
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/parsers/__init__.py
trunk/docutils/docutils/transforms/references.py
trunk/docutils/test/data/help/docutils.rst
trunk/docutils/test/data/help/rst2html.rst
trunk/docutils/test/data/help/rst2latex.rst
trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
trunk/docutils/test/test_parsers/test_rst/test_targets.py
trunk/docutils/test/test_transforms/test_hyperlinks.py
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/HISTORY.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -47,6 +47,9 @@
- Remove "name" from `reference.valid_attributes`.
- Remove the internal attribute `Targetable.indirect_reference_name`.
+ - "lazy IDs": `document.note_explicit_target()` and
+ `document.note_anonymous_target()` generate identifiers for indirect
+ or external targets only if the `legacy_ids`_ setting is True.
* docutils/parsers/__init__.py
Modified: trunk/docutils/RELEASE-NOTES.rst
===================================================================
--- trunk/docutils/RELEASE-NOTES.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/RELEASE-NOTES.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -233,6 +233,8 @@
rST parser:
- Warn if a `"figure"`_ directive is missing both caption and legend.
+ - Don't generate identifiers for indirect or external targets
+ (unless legacy_ids_ is True).
- Generate identifiers for implicit targets (mainly sections) only if
there is a cross-link to the target [#cross-links]_ and no "explicit"
identifier (unless legacy_ids_ is True).
Modified: trunk/docutils/docs/ref/rst/directives.rst
===================================================================
--- trunk/docutils/docs/ref/rst/directives.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/docs/ref/rst/directives.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -57,6 +57,7 @@
`specific admonitions`_.
+.. _specific admonitions:
.. _attention:
.. _caution:
.. _danger:
@@ -760,7 +761,7 @@
See Epigraph_ above for an analogous example.
-.. compound:
+.. _compound:
Compound Paragraph
==================
@@ -1152,8 +1153,7 @@
Document Parts
----------------
-.. A ``_contents:`` hyperlink here became id "contents-1"
- (name clash with the generated ToC)
+.. _contents:
Table of Contents
=================
@@ -1795,6 +1795,7 @@
A URI reference to a raw data file to be included.
+.. _class:
.. _class directive:
.. _rst-class:
@@ -2257,8 +2258,7 @@
:alt: example picture
:class: large-pics
- is the recommended syntax alternative to a preceding
- `class directive`_ ::
+ is the recommended syntax alternative to a preceding "class_" directive ::
.. class:: large-pics
.. image:: bild.png
Modified: trunk/docutils/docs/user/config.rst
===================================================================
--- trunk/docutils/docs/user/config.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/docs/user/config.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -799,9 +799,10 @@
Keep element identifiers_ compatible to Docutils ≤ 0.22.
If "legacy_ids" is False or with the command line option ``--lazy-ids``,
-the generation of identifiers_ from the `reference names`_ of
-`implicit targets`_ is done after parsing is complete and only
-if required by an internal cross-link [#cross-link]_.
+no identifiers_ are generated for `external <external targets_>`__ and
+`indirect targets`_. The generation of identifiers_ from the
+`reference names`_ of `implicit targets`_ is done after parsing is
+complete and only if required by an internal cross-link [#cross-link]_.
An existing identifier from an `explicit target`_ is re-used instead of
generating an additional identifier for the "implicit" reference name.
@@ -2689,6 +2690,7 @@
.. _explicit target:
.. _explicit targets: ../ref/rst/restructuredtext.html#explicit-hyperlink-targets
.. _explicit internal target: ../ref/rst/restructuredtext.html#internal-hyperlink-targets
+.. _external targets: ../ref/rst/restructuredtext.html#external-hyperlink-targets
.. _field lists: ../ref/rst/restructuredtext.html#field-lists
.. _field names: ../ref/rst/restructuredtext.html#field-names
.. _footnotes: ../ref/rst/restructuredtext.html#footnotes
@@ -2697,6 +2699,7 @@
.. _implicit hyperlink targets:
.. _implicit target:
.. _implicit targets: ../ref/rst/restructuredtext.html#implicit-hyperlink-targets
+.. _indirect targets: ../ref/rst/restructuredtext.html#indirect-hyperlink-targets
.. _interpreted text role: ../ref/rst/restructuredtext.html#interpreted-text
.. _inline markup recognition rules:
../ref/rst/restructuredtext.html#inline-markup-recognition-rules
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/docutils/nodes.py 2026-07-14 13:32:05 UTC (rev 10382)
@@ -2177,7 +2177,9 @@
def note_explicit_target(self, target: Element,
msgnode: Element|None = None) -> None:
self.note_names(target, msgnode, explicit=True)
- self.set_id(target, msgnode)
+ if (getattr(self.settings, "legacy_ids", True)
+ or 'refuri' not in target and 'refname' not in target):
+ self.set_id(target, msgnode)
def note_refname(self, node: Element) -> None:
self.refnames.setdefault(node['refname'], []).append(node)
@@ -2191,7 +2193,9 @@
self.note_refname(target)
def note_anonymous_target(self, target: target) -> None:
- self.set_id(target)
+ if (getattr(self.settings, "legacy_ids", True)
+ or 'refuri' not in target and 'refname' not in target):
+ self.set_id(target)
def note_autofootnote(self, footnote: footnote) -> None:
self.set_id(footnote)
Modified: trunk/docutils/docutils/parsers/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/__init__.py 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/docutils/parsers/__init__.py 2026-07-14 13:32:05 UTC (rev 10382)
@@ -51,7 +51,8 @@
['--legacy-ids'],
{'action': 'store_true', 'default': True,
'validator': frontend.validate_boolean}),
- ('Generate IDs for implicit targets only if required.',
+ ('Generate IDs for implicit targets only if required; '
+ 'no IDs for external and indirect targets.',
['--lazy-ids'],
{'dest': 'legacy_ids', 'action': 'store_false'}),
('Validate the document tree after parsing.',
@@ -101,7 +102,7 @@
'xml': 'docutils.parsers.docutils_xml',
# 3rd-party Markdown parsers
'myst': 'myst_parser.docutils_',
- # 'pycmark': works out of the box
+ # 'pycmark': works out of the box (with `legacy_ids`)
# dispatcher for 3rd-party Markdown parsers
'commonmark': 'docutils.parsers.commonmark_wrapper',
'markdown': 'docutils.parsers.commonmark_wrapper',
Modified: trunk/docutils/docutils/transforms/references.py
===================================================================
--- trunk/docutils/docutils/transforms/references.py 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/docutils/transforms/references.py 2026-07-14 13:32:05 UTC (rev 10382)
@@ -178,8 +178,12 @@
break
else:
if not target['ids']:
- # Propagated target.
- target = self.document.ids[target['refid']]
+ if 'refid' in target: # propagated target
+ target = self.document.ids[target['refid']]
+ elif 'refname' in target: # indirect target
+ target = self.document.names[target['refname']]
+ else:
+ self.document.set_id(target)
continue
ref['refid'] = target['ids'][0]
self.document.note_refid(ref)
@@ -254,13 +258,17 @@
reftarget = self.document.ids.get(refid)
else:
reftarget = self.document.names.get(refname)
- refid = self.document.nameids.get(refname)
- if reftarget and not refid:
- refid = self.document.set_id(reftarget)
+ if getattr(self.document.settings, "legacy_ids", True):
+ refid = self.document.nameids.get(refname)
if not reftarget:
self.nonexistent_indirect_target(target)
return
- reftarget.note_referenced_by(id=refid)
+
+ if refid:
+ reftarget.note_referenced_by(id=refid)
+ else:
+ reftarget.note_referenced_by(name=refname)
+
if (isinstance(reftarget, nodes.target)
and not reftarget.resolved
and reftarget.hasattr('refname')):
@@ -277,12 +285,12 @@
elif reftarget.hasattr('refid'):
target['refid'] = reftarget['refid']
self.document.note_refid(target)
- elif reftarget['ids']:
+ else: # internal target
+ if not refid:
+ refid = self.document.set_id(reftarget)
target['refid'] = refid
self.document.note_refid(target)
- else:
- self.nonexistent_indirect_target(target)
- return
+ # Mark target as resolved:
if refname is not None:
del target['refname']
target.resolved = True
@@ -1003,9 +1011,9 @@
elif target['ids']:
naming = target['ids'][0]
else:
- # Hack: Propagated targets always have their refid
- # attribute set.
- naming = target['refid']
+ # Propagated target: "ids" and "names" attributes moved
+ # to the node indicated by "refid" or "refname".
+ naming = target.get('refid') or target.get('refname', '???')
self.document.reporter.info(
f'Hyperlink target "{naming}" is not referenced.',
base_node=target)
Modified: trunk/docutils/test/data/help/docutils.rst
===================================================================
--- trunk/docutils/test/data/help/docutils.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/data/help/docutils.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -90,7 +90,8 @@
Maximal number of characters in an input line.
(default 10 000)
--legacy-ids Keep IDs backwards compatible. (default)
---lazy-ids Generate IDs for implicit targets only if required.
+--lazy-ids Generate IDs for implicit targets only if required; no
+ IDs for external and indirect targets.
--validate Validate the document tree after parsing.
--no-validation Do not validate the document tree. (default)
Modified: trunk/docutils/test/data/help/rst2html.rst
===================================================================
--- trunk/docutils/test/data/help/rst2html.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/data/help/rst2html.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -91,7 +91,8 @@
Maximal number of characters in an input line.
(default 10 000)
--legacy-ids Keep IDs backwards compatible. (default)
---lazy-ids Generate IDs for implicit targets only if required.
+--lazy-ids Generate IDs for implicit targets only if required; no
+ IDs for external and indirect targets.
--validate Validate the document tree after parsing.
--no-validation Do not validate the document tree. (default)
Modified: trunk/docutils/test/data/help/rst2latex.rst
===================================================================
--- trunk/docutils/test/data/help/rst2latex.rst 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/data/help/rst2latex.rst 2026-07-14 13:32:05 UTC (rev 10382)
@@ -91,7 +91,8 @@
Maximal number of characters in an input line.
(default 10 000)
--legacy-ids Keep IDs backwards compatible. (default)
---lazy-ids Generate IDs for implicit targets only if required.
+--lazy-ids Generate IDs for implicit targets only if required; no
+ IDs for external and indirect targets.
--validate Validate the document tree after parsing.
--no-validation Do not validate the document tree. (default)
Modified: trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt 2026-07-14 13:32:05 UTC (rev 10382)
@@ -497,8 +497,8 @@
<reference refid="subtitle">
subtitle
.
- <target anonymous="1" ids="target-1" refuri="http://www.python.org/">
- <target anonymous="1" ids="target-2" refuri="https://docutils.sourceforge.io/">
+ <target anonymous="1" refuri="http://www.python.org/">
+ <target anonymous="1" refuri="https://docutils.sourceforge.io/">
<paragraph>
The default role for interpreted text is
<title_reference>
@@ -1054,7 +1054,7 @@
<reference anonymous="1" refid="label">
hyperlink reference
.
- <target anonymous="1" ids="target-3" refid="label">
+ <target anonymous="1" refid="label">
<footnote auto="1" backrefs="footnote-reference-2" ids="footnote-2" names="3">
<label>
3
@@ -1142,7 +1142,7 @@
<footnote_reference auto="1" ids="footnote-reference-11" refid="footnote-6">
5
".
- <target ids="python" names="python" refuri="http://www.python.org/">
+ <target names="python" refuri="http://www.python.org/">
<paragraph>
Targets may be indirect and anonymous. Thus
<reference anonymous="1" refid="another-target">
@@ -1152,7 +1152,7 @@
<reference refid="another-target">
Targets
section.
- <target anonymous="1" ids="target-4" refid="another-target">
+ <target anonymous="1" refid="another-target">
<paragraph>
Here's a
<problematic ids="problematic-2" refid="system-message-4">
@@ -1265,7 +1265,7 @@
<footnote_reference auto="1" ids="footnote-reference-16" refid="footnote-9">
8
.
- <target anonymous="1" ids="target-5" refuri="https://docutils.sourceforge.io/docs/ref/rst/directives.html">
+ <target anonymous="1" refuri="https://docutils.sourceforge.io/docs/ref/rst/directives.html">
<section ids="document-parts" names="document\ parts">
<title auto="1" refid="toc-entry-43">
<generated classes="sectnum">
@@ -1627,7 +1627,7 @@
And, by the way...
<paragraph>
You can make up your own admonition too.
- <target ids="docutils" names="docutils" refuri="https://docutils.sourceforge.io/">
+ <target names="docutils" refuri="https://docutils.sourceforge.io/">
<section ids="topics-sidebars-and-rubrics" names="topics,\ sidebars,\ and\ rubrics">
<title auto="1" refid="toc-entry-47">
<generated classes="sectnum">
@@ -2004,7 +2004,7 @@
<inline classes="ln">
2
.. footer:: Document footer
- <target ids="pygments" names="pygments" refuri="http://pygments.org/">
+ <target names="pygments" refuri="http://pygments.org/">
<section ids="meta" names="meta">
<title auto="1" refid="toc-entry-53">
<generated classes="sectnum">
@@ -2019,7 +2019,7 @@
9
is used to specify metadata to be stored in,
e.g., HTML META tags or ODT file properties.
- <target anonymous="1" ids="target-6" refuri="https://docutils.sourceforge.io/docs/ref/rst/directives.html#metadata">
+ <target anonymous="1" refuri="https://docutils.sourceforge.io/docs/ref/rst/directives.html#metadata">
<section ids="substitution-definitions" names="substitution\ definitions">
<title auto="1" refid="toc-entry-34">
<generated classes="sectnum">
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2026-07-14 13:32:05 UTC (rev 10382)
@@ -44,7 +44,7 @@
settings = get_default_settings(Parser)
settings.warning_stream = ''
settings.halt_level = 5
- settings.legacy_ids = False
+ settings.legacy_ids = False # except for pycmark (see below)
for name, cases in totest.items():
if name == 'with transforms':
continue # see test_publish() below
@@ -55,7 +55,10 @@
self.skipTest('no markdown parser available')
if name == 'include_parsed_code' and not with_pygments:
self.skipTest('syntax highlight requires pygments')
- document = new_document('test data', settings.copy())
+ mysettings = settings.copy()
+ if name == 'include_markdown':
+ mysettings.legacy_ids = True # keep pycmark happy
+ document = new_document('test data', mysettings)
parser.parse(case_input, document)
output = document.pformat()
self.assertEqual(case_expected, output)
@@ -1567,7 +1570,7 @@
<document source="test data">
<paragraph>
Include Markdown source.
- <section depth="1">
+ <section depth="1" ids="section-1">
<title>
Title 1
<paragraph>
Modified: trunk/docutils/test/test_parsers/test_rst/test_targets.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_targets.py 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/test_parsers/test_rst/test_targets.py 2026-07-14 13:32:05 UTC (rev 10382)
@@ -86,11 +86,11 @@
<document source="test data">
<paragraph>
External hyperlink targets:
- <target ids="one-liner" names="one-liner" refuri="http://structuredtext.sourceforge.net">
- <target ids="starts-on-this-line" names="starts-on-this-line" refuri="http://structuredtext.sourceforge.net">
- <target ids="entirely-below" names="entirely-below" refuri="http://structuredtext.sourceforge.net">
- <target ids="escaped-whitespace" names="escaped-whitespace" refuri="http://example.org/a path with spaces.html">
- <target ids="not-indirect" names="not-indirect" refuri="uri_">
+ <target names="one-liner" refuri="http://structuredtext.sourceforge.net">
+ <target names="starts-on-this-line" refuri="http://structuredtext.sourceforge.net">
+ <target names="entirely-below" refuri="http://structuredtext.sourceforge.net">
+ <target names="escaped-whitespace" refuri="http://example.org/a path with spaces.html">
+ <target names="not-indirect" refuri="uri_">
"""],
["""\
Indirect hyperlink targets:
@@ -103,8 +103,8 @@
<document source="test data">
<paragraph>
Indirect hyperlink targets:
- <target ids="target1" names="target1" refname="reference">
- <target ids="target2" names="target2" refname="phrase-link reference">
+ <target names="target1" refname="reference">
+ <target names="target2" refname="phrase-link reference">
"""],
["""\
.. _a long target name:
@@ -156,7 +156,7 @@
<document source="test data">
<paragraph>
External hyperlink:
- <target ids="target" names="target" refuri="http://www.python.org/">
+ <target names="target" refuri="http://www.python.org/">
"""],
["""\
.. _email: jd...@ex...
@@ -166,8 +166,8 @@
""",
"""\
<document source="test data">
- <target ids="email" names="email" refuri="mailto:jd...@ex...">
- <target ids="multi-line-email" names="multi-line\\ email" refuri="mailto:jd...@ex...">
+ <target names="email" refuri="mailto:jd...@ex...">
+ <target names="multi-line\\ email" refuri="mailto:jd...@ex...">
"""],
["""\
Malformed target:
@@ -189,7 +189,7 @@
malformed hyperlink target.
<paragraph>
Target beginning with an underscore:
- <target ids="target" names="_target" refuri="OK">
+ <target names="_target" refuri="OK">
"""],
["""\
Duplicate external targets (different URIs):
@@ -202,11 +202,11 @@
<document source="test data">
<paragraph>
Duplicate external targets (different URIs):
- <target dupnames="target" ids="target" refuri="first">
+ <target dupnames="target" refuri="first">
<system_message level="2" line="5" source="test data" type="WARNING">
<paragraph>
Duplicate explicit target name: "target".
- <target dupnames="target" ids="target-1" refuri="second">
+ <target dupnames="target" refuri="second">
"""],
["""\
Duplicate external targets (same URIs):
@@ -219,11 +219,11 @@
<document source="test data">
<paragraph>
Duplicate external targets (same URIs):
- <target ids="target" names="target" refuri="first">
+ <target names="target" refuri="first">
<system_message level="1" line="5" source="test data" type="INFO">
<paragraph>
Duplicate name "target" for external target "first".
- <target dupnames="target" ids="target-1" refuri="first">
+ <target dupnames="target" refuri="first">
"""],
["""\
Duplicate external targets (embedded/explicit, same URIs):
@@ -250,7 +250,7 @@
<system_message level="1" line="7" source="test data" type="INFO">
<paragraph>
Duplicate name "example" for external target "example.rst".
- <target dupnames="example" ids="example-1" refuri="example.rst">
+ <target dupnames="example" refuri="example.rst">
"""],
["""\
Duplicate indirect _`targets` (same refname):
@@ -268,11 +268,11 @@
<target ids="targets" names="targets">
targets
(same refname):
- <target ids="link" names="link" refname="targets">
+ <target names="link" refname="targets">
<system_message level="1" line="5" source="test data" type="INFO">
<paragraph>
Duplicate name "link" for external target "targets".
- <target dupnames="link" ids="link-1" refname="targets">
+ <target dupnames="link" refname="targets">
<paragraph>
do not conflict. The reference name can be used in a \n\
<reference refname="link">
@@ -477,15 +477,15 @@
<system_message level="2" line="16" source="test data" type="WARNING">
<paragraph>
Duplicate explicit target name: "target".
- <target dupnames="target" ids="target-3" refuri="Explicit_external_target">
+ <target dupnames="target" refuri="Explicit_external_target">
<line_block>
<line>
Do not insert <system_message> element for duplicate
<line>
- <target dupnames="target" ids="target-4">
+ <target dupnames="target" ids="target-3">
target
, if this results in an invalid doctree.
- <rubric dupnames="target" ids="target-5">
+ <rubric dupnames="target" ids="target-4">
directive with target
<field_list>
<field>
@@ -496,7 +496,7 @@
with
<field>
<field_name>
- <target dupnames="target" ids="target-6">
+ <target dupnames="target" ids="target-5">
target
<field_body>
<paragraph>
@@ -523,8 +523,8 @@
<system_message level="2" line="3" source="test data" type="WARNING">
<paragraph>
malformed hyperlink target.
- <target ids="escaped-colon" names="escaped\\ colon:" refuri="OK">
- <target ids="unescaped-colon-quoted" names="unescaped\\ colon,\\ quoted:" refuri="OK">
+ <target names="escaped\\ colon:" refuri="OK">
+ <target names="unescaped\\ colon,\\ quoted:" refuri="OK">
"""],
])
@@ -768,7 +768,7 @@
<document source="test data">
<paragraph>
Anonymous external hyperlink target:
- <target anonymous="1" ids="target-1" refuri="http://w3c.org/">
+ <target anonymous="1" refuri="http://w3c.org/">
"""],
["""\
Anonymous external hyperlink target:
@@ -779,7 +779,7 @@
<document source="test data">
<paragraph>
Anonymous external hyperlink target:
- <target anonymous="1" ids="target-1" refuri="http://w3c.org/">
+ <target anonymous="1" refuri="http://w3c.org/">
"""],
["""\
Anonymous indirect hyperlink target:
@@ -790,7 +790,7 @@
<document source="test data">
<paragraph>
Anonymous indirect hyperlink target:
- <target anonymous="1" ids="target-1" refname="reference">
+ <target anonymous="1" refname="reference">
"""],
["""\
Anonymous external hyperlink target, not indirect:
@@ -803,8 +803,8 @@
<document source="test data">
<paragraph>
Anonymous external hyperlink target, not indirect:
- <target anonymous="1" ids="target-1" refuri="uri_">
- <target anonymous="1" ids="target-2" refuri="thisURIendswithanunderscore_">
+ <target anonymous="1" refuri="uri_">
+ <target anonymous="1" refuri="thisURIendswithanunderscore_">
"""],
["""\
Anonymous indirect hyperlink targets:
@@ -817,8 +817,8 @@
<document source="test data">
<paragraph>
Anonymous indirect hyperlink targets:
- <target anonymous="1" ids="target-1" refname="reference">
- <target anonymous="1" ids="target-2" refname="a very long reference">
+ <target anonymous="1" refname="reference">
+ <target anonymous="1" refname="a very long reference">
"""],
["""\
Mixed anonymous & named indirect hyperlink targets:
@@ -839,19 +839,19 @@
<document source="test data">
<paragraph>
Mixed anonymous & named indirect hyperlink targets:
- <target anonymous="1" ids="target-1" refname="reference">
- <target anonymous="1" ids="target-2" refname="reference">
- <target anonymous="1" ids="target-3" refname="reference">
- <target ids="target1" names="target1" refname="reference">
+ <target anonymous="1" refname="reference">
+ <target anonymous="1" refname="reference">
+ <target anonymous="1" refname="reference">
+ <target names="target1" refname="reference">
<system_message level="2" line="7" source="test data" type="WARNING">
<paragraph>
Explicit markup ends without a blank line; unexpected unindent.
<paragraph>
no blank line
- <target ids="target2" names="target2" refname="reference">
- <target anonymous="1" ids="target-4" refname="reference">
- <target anonymous="1" ids="target-5" refname="reference">
- <target anonymous="1" ids="target-6" refname="reference">
+ <target names="target2" refname="reference">
+ <target anonymous="1" refname="reference">
+ <target anonymous="1" refname="reference">
+ <target anonymous="1" refname="reference">
<system_message level="2" line="13" source="test data" type="WARNING">
<paragraph>
Explicit markup ends without a blank line; unexpected unindent.
Modified: trunk/docutils/test/test_transforms/test_hyperlinks.py
===================================================================
--- trunk/docutils/test/test_transforms/test_hyperlinks.py 2026-07-14 13:31:29 UTC (rev 10381)
+++ trunk/docutils/test/test_transforms/test_hyperlinks.py 2026-07-14 13:32:05 UTC (rev 10382)
@@ -594,7 +594,8 @@
"""],
])
-totest['explicit hyperlinks legacy'] = ({'legacy_ids': True}, [
+# explicit internal hyperlinks are not affected by "legacy_ids"
+totest['explicit internal hyperlinks (legacy_ids)'] = ({'legacy_ids': True}, [
["""\
.. _internal hyperlink:
@@ -643,24 +644,6 @@
The results of the transform are not visible at the XML level.
"""],
["""\
-.. _chained:
-__ http://anonymous
-
-Anonymous__ and chained_ both refer to the same URI.
-""",
-"""\
-<document source="test data">
- <target refid="chained">
- <target anonymous="1" ids="target-1 chained" names="chained" refuri="http://anonymous">
- <paragraph>
- <reference anonymous="1" refuri="http://anonymous">
- Anonymous
- and \n\
- <reference refuri="http://anonymous">
- chained
- both refer to the same URI.
-"""],
-["""\
.. _a:
.. _b:
@@ -730,125 +713,209 @@
b
"""],
["""\
-.. _external hyperlink: http://uri
+Unknown reference_.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Unknown \n\
+ <problematic ids="problematic-1" refid="system-message-1">
+ reference_
+ .
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Unknown target name: "reference".
+"""],
+["""\
+Duplicate manual footnote labels, with reference ([1]_):
-`External hyperlink`_ reference.
+.. [1] Footnote.
+
+.. [1] Footnote.
""",
"""\
<document source="test data">
- <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
<paragraph>
- <reference refuri="http://uri">
- External hyperlink
- reference.
+ Duplicate manual footnote labels, with reference (
+ <problematic ids="footnote-reference-1" refid="system-message-1">
+ [1]_
+ ):
+ <footnote dupnames="1" ids="footnote-1">
+ <label>
+ 1
+ <paragraph>
+ Footnote.
+ <footnote dupnames="1" ids="footnote-2">
+ <label>
+ 1
+ <system_message backrefs="footnote-2" level="2" line="5" source="test data" type="WARNING">
+ <paragraph>
+ Duplicate explicit target name: "1".
+ <paragraph>
+ Footnote.
+ <system_message backrefs="footnote-reference-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Duplicate target name, cannot be used as a unique reference: "1".
"""],
+])
+
+totest['explicit internal hyperlinks (lazy_ids)'] = ({'legacy_ids': False},
+ # all samples compile as before
+ totest['explicit internal hyperlinks (legacy_ids)'][1])
+
+# implicit, indirect, and external hyperlinks get IDs with "legacy_ids"
+totest['various hyperlinks (legacy_ids)'] = ({'legacy_ids': True}, [
["""\
-.. _external hyperlink: http://uri
-.. _indirect target: `external hyperlink`_
+.. contents:: Table of Contents
+.. _indirect reference to the table of contents: `table of contents`_
+
+Section
+=======
+
+Testing an `indirect reference to the table of contents`_.
""",
"""\
<document source="test data">
- <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
- <target ids="indirect-target" names="indirect\\ target" refuri="http://uri">
- <system_message level="1" line="2" source="test data" type="INFO">
+ <topic classes="contents" ids="table-of-contents" names="table\\ of\\ contents">
+ <title>
+ Table of Contents
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ <reference ids="toc-entry-1" refid="section">
+ Section
+ <target ids="indirect-reference-to-the-table-of-contents" names="indirect\\ reference\\ to\\ the\\ table\\ of\\ contents" refid="table-of-contents">
+ <section ids="section" names="section">
+ <title refid="toc-entry-1">
+ Section
<paragraph>
- Hyperlink target "indirect target" is not referenced.
+ Testing an \n\
+ <reference refid="table-of-contents">
+ indirect reference to the table of contents
+ .
"""],
["""\
-.. _chained:
-.. _external hyperlink: http://uri
+.. _explicit target:
-`External hyperlink`_ reference
-and a chained_ reference too.
+Title
+-----
+
+Let's reference the `explicit target`_ to avoid an irrelevant error.
""",
"""\
<document source="test data">
- <target refid="chained">
- <target ids="external-hyperlink chained" names="external\\ hyperlink chained" refuri="http://uri">
- <paragraph>
- <reference refuri="http://uri">
- External hyperlink
- reference
- and a \n\
- <reference refuri="http://uri">
- chained
- reference too.
+ <target refid="explicit-target">
+ <section ids="title explicit-target" names="title explicit\\ target">
+ <title>
+ Title
+ <paragraph>
+ Let's reference the \n\
+ <reference refid="explicit-target">
+ explicit target
+ to avoid an irrelevant error.
"""],
["""\
-.. _external hyperlink: http://uri
-.. _indirect hyperlink: `external hyperlink`_
+target1_ should be an alias of target2_, not the Title.
-`Indirect hyperlink`_ reference.
+.. _target1:
+.. _target2: URI
+
+Title
+=====
""",
"""\
<document source="test data">
- <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
- <target ids="indirect-hyperlink" names="indirect\\ hyperlink" refuri="http://uri">
<paragraph>
- <reference refuri="http://uri">
- Indirect hyperlink
- reference.
+ <reference refuri="URI">
+ target1
+ should be an alias of \n\
+ <reference refuri="URI">
+ target2
+ , not the Title.
+ <target refid="target1">
+ <target ids="target2 target1" names="target2 target1" refuri="URI">
+ <section ids="title" names="title">
+ <title>
+ Title
"""],
["""\
-.. _external hyperlink: http://uri
-.. _chained:
-.. _indirect hyperlink: `external hyperlink`_
+foo
+---
-Chained_ `indirect hyperlink`_ reference.
+With legacy_ids = True, an explicit target _`foo` overrides a
+homonymous implicit target but gets a "diambiguated" identifier.
+
+The reference foo_ points to the explicit target.
+Referencing from an external document requires the
+non-obvious fragment identifier "#foo-1".
""",
"""\
<document source="test data">
- <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
- <target refuri="http://uri">
- <target ids="indirect-hyperlink chained" names="indirect\\ hyperlink chained" refuri="http://uri">
- <paragraph>
- <reference refuri="http://uri">
- Chained
- \n\
- <reference refuri="http://uri">
- indirect hyperlink
- reference.
+ <section dupnames="foo" ids="foo">
+ <title>
+ foo
+ <system_message backrefs="foo-1" level="1" line="5" source="test data" type="INFO">
+ <paragraph>
+ Target name overrides implicit target name "foo".
+ <paragraph>
+ With legacy_ids = True, an explicit target \n\
+ <target ids="foo-1" names="foo">
+ foo
+ overrides a
+ homonymous implicit target but gets a "diambiguated" identifier.
+ <paragraph>
+ The reference \n\
+ <reference refid="foo-1">
+ foo
+ points to the explicit target.
+ Referencing from an external document requires the
+ non-obvious fragment identifier "#foo-1".
"""],
["""\
-.. __: http://full
-__
-__ http://simplified
-.. _external: http://indirect.external
-__ external_
-__
+foo
+---
-`Full syntax anonymous external hyperlink reference`__,
-`chained anonymous external reference`__,
-`simplified syntax anonymous external hyperlink reference`__,
-`indirect anonymous hyperlink reference`__,
-`internal anonymous hyperlink reference`__.
+If an implicit target precedes a homonymous explicit target _`foo`,
+the explicit target takes over the reference name but not the identifier.
+
+The reference foo_ points to the explicit target. However, referencing from
+an external document requires the non-obvious fragment identifier "#foo-1".
""",
"""\
<document source="test data">
- <target anonymous="1" ids="target-1" refuri="http://full">
- <target anonymous="1" refid="target-2">
- <target anonymous="1" ids="target-3 target-2" refuri="http://simplified">
- <target ids="external" names="external" refuri="http://indirect.external">
- <target anonymous="1" ids="target-4" refuri="http://indirect.external">
- <target anonymous="1" refid="target-5">
- <paragraph ids="target-5">
- <reference anonymous="1" refuri="http://full">
- Full syntax anonymous external hyperlink reference
- ,
- <reference anonymous="1" refuri="http://simplified">
- chained anonymous external reference
- ,
- <reference anonymous="1" refuri="http://simplified">
- simplified syntax anonymous external hyperlink reference
- ,
- <reference anonymous="1" refuri="http://indirect.external">
- indirect anonymous hyperlink reference
- ,
- <reference anonymous="1" refid="target-5">
- internal anonymous hyperlink reference
- .
+ <section dupnames="foo" ids="foo">
+ <title>
+ foo
+ <system_message backrefs="foo-1" level="1" line="5" source="test data" type="INFO">
+ <paragraph>
+ Target name overrides implicit target name "foo".
+ <paragraph>
+ If an implicit target precedes a homonymous explicit target \n\
+ <target ids="foo-1" names="foo">
+ foo
+ ,
+ the explicit target takes over the reference name but not the identifier.
+ <paragraph>
+ The reference \n\
+ <reference refid="foo-1">
+ foo
+ points to the explicit target. However, referencing from
+ an external document requires the non-obvious fragment identifier "#foo-1".
"""],
["""\
+.. _external hyperlink: http://uri
+
+`External hyperlink`_ reference.
+""",
+"""\
+<document source="test data">
+ <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
+ <paragraph>
+ <reference refuri="http://uri">
+ External hyperlink
+ reference.
+"""],
+["""\
Duplicate external target_'s (different URIs):
.. _target: first
@@ -889,29 +956,73 @@
<target dupnames="target" ids="target-1" refuri="second">
"""],
["""\
-Several__ anonymous__ hyperlinks__, but not enough targets.
+.. _chained:
+.. _external hyperlink: http://uri
-__ http://example.org
+`External hyperlink`_ reference
+and a chained_ reference too.
""",
"""\
<document source="test data">
+ <target refid="chained">
+ <target ids="external-hyperlink chained" names="external\\ hyperlink chained" refuri="http://uri">
<paragraph>
- <problematic ids="problematic-1" refid="system-message-1">
- Several__
- \n\
- <problematic ids="problematic-2" refid="system-message-1">
- anonymous__
- \n\
- <problematic ids="problematic-3" refid="system-message-1">
- hyperlinks__
- , but not enough targets.
- <target anonymous="1" ids="target-1" refuri="http://example.org">
- <system_message backrefs="problematic-1 problematic-2 problematic-3" ids="system-message-1" level="3" source="test data" type="ERROR">
+ <reference refuri="http://uri">
+ External hyperlink
+ reference
+ and a \n\
+ <reference refuri="http://uri">
+ chained
+ reference too.
+"""],
+["""\
+.. _external hyperlink: http://uri
+.. _indirect target: `external hyperlink`_
+""",
+"""\
+<document source="test data">
+ <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
+ <target ids="indirect-target" names="indirect\\ target" refuri="http://uri">
+ <system_message level="1" line="2" source="test data" type="INFO">
<paragraph>
- Anonymous hyperlink mismatch: 3 references but 1 targets.
- See "backrefs" attribute for IDs.
+ Hyperlink target "indirect target" is not referenced.
"""],
["""\
+.. _external hyperlink: http://uri
+.. _indirect hyperlink: `external hyperlink`_
+
+`Indirect hyperlink`_ reference.
+""",
+"""\
+<document source="test data">
+ <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
+ <target ids="indirect-hyperlink" names="indirect\\ hyperlink" refuri="http://uri">
+ <paragraph>
+ <reference refuri="http://uri">
+ Indirect hyperlink
+ reference.
+"""],
+["""\
+.. _external hyperlink: http://uri
+.. _chained:
+.. _indirect hyperlink: `external hyperlink`_
+
+Chained_ `indirect hyperlink`_ reference.
+""",
+"""\
+<document source="test data">
+ <target ids="external-hyperlink" names="external\\ hyperlink" refuri="http://uri">
+ <target refuri="http://uri">
+ <target ids="indirect-hyperlink chained" names="indirect\\ hyperlink chained" refuri="http://uri">
+ <paragraph>
+ <reference refuri="http://uri">
+ Chained
+ \n\
+ <reference refuri="http://uri">
+ indirect hyperlink
+ reference.
+"""],
+["""\
.. _external: http://uri
.. _indirect: external_
.. _internal:
@@ -1036,57 +1147,89 @@
to an image with target (sic!).
"""],
["""\
-Unknown reference_.
+.. __: http://full
+__
+__ http://simplified
+.. _external: http://indirect.external
+__ external_
+__
+
+`Full syntax anonymous external hyperlink reference`__,
+`chained anonymous external reference`__,
+`simplified syntax anonymous external hyperlink reference`__,
+`indirect anonymous hyperlink reference`__,
+`internal anonymous hyperlink reference`__.
""",
"""\
<document source="test data">
- <paragraph>
- Unknown \n\
- <problematic ids="problematic-1" refid="system-message-1">
- reference_
+ <target anonymous="1" ids="target-1" refuri="http://full">
+ <target anonymous="1" refid="target-2">
+ <target anonymous="1" ids="target-3 target-2" refuri="http://simplified">
+ <target ids="external" names="external" refuri="http://indirect.external">
+ <target anonymous="1" ids="target-4" refuri="http://indirect.external">
+ <target anonymous="1" refid="target-5">
+ <paragraph ids="target-5">
+ <reference anonymous="1" refuri="http://full">
+ Full syntax anonymous external hyperlink reference
+ ,
+ <reference anonymous="1" refuri="http://simplified">
+ chained anonymous external reference
+ ,
+ <reference anonymous="1" refuri="http://simplified">
+ simplified syntax anonymous external hyperlink reference
+ ,
+ <reference anonymous="1" refuri="http://indirect.external">
+ indirect anonymous hyperlink reference
+ ,
+ <reference anonymous="1" refid="target-5">
+ internal anonymous hyperlink reference
.
- <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
- <paragraph>
- Unknown target name: "reference".
"""],
["""\
-Duplicate manual footnote labels, with reference ([1]_):
+.. _chained:
+__ http://anonymous
-.. [1] Footnote.
+Anonymous__ and chained_ both refer to the same URI.
+""",
+"""\
+<document source="test data">
+ <target refid="chained">
+ <target anonymous="1" ids="target-1 chained" names="chained" refuri="http://anonymous">
+ <paragraph>
+ <reference anonymous="1" refuri="http://anonymous">
+ Anonymous
+ and \n\
+ <reference refuri="http://anonymous">
+ chained
+ both refer to the same URI.
+"""],
+["""\
+Several__ anonymous__ hyperlinks__, but not enough targets.
-.. [1] Footnote.
+__ http://example.org
""",
"""\
<document source="test data">
<paragraph>
- Duplicate manual footnote labels, with reference (
- <problematic ids="footnote-reference-1" refid="system-message-1">
- [1]_
- ):
- <footnote dupnames="1" ids="footnote-1">
- <label>
- 1
+ <problematic ids="problematic-1" refid="system-message-1">
+ Several__
+ \n\
+ <problematic ids="problematic-2" refid="system-message-1">
+ anonymous__
+ \n\
+ <problematic ids="problematic-3" refid="system-message-1">
+ hyperlinks__
+ , but not enough targets.
+ <target anonymous="1" ids="target-1" refuri="http://example.org">
+ <system_message backrefs="problematic-1 problematic-2 problematic-3" ids="system-message-1" level="3" source="test data" type="ERROR">
<paragraph>
- Footnote.
- <footnote dupnames="1" ids="footnote-2">
- <label>
- 1
- <system_message backrefs="footnote-2" level="2" line="5" source="test data" type="WARNING">
- <paragraph>
- Duplicate explicit target name: "1".
- <paragraph>
- Footnote.
- <system_message backrefs="footnote-reference-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
- <paragraph>
- Duplicate target name, cannot be used as a unique reference: "1".
+ Anonymous hyperlink mismatch: 3 references but 1 targets.
+ See "backrefs" attribute for IDs.
"""],
])
-totest['explicit hyperlinks'] = ({'legacy_ids': False},
- # all samples compile as before
- totest['explicit hyperlinks legacy'][1])
-
-totest['implicit hyperlinks legacy'] = ({'legacy_ids': True}, [
+# implicit, indirect, and external hyperlinks get *no* IDs with "lazy_ids"
+totest['various hyperlinks (lazy_ids)'] = ({'legacy_ids': False}, [
["""\
.. contents:: Table of Contents
.. _indirect reference to the table of contents: `table of contents`_
@@ -1106,7 +1249,7 @@
<paragraph>
<reference ids="toc-entry-1" refid="section">
Section
- <target ids="indirect-reference-to-the-table-of-contents" names="indirect\\ reference\\ to\\ the\\ table\\ of\\ contents" refid="table-of-contents">
+ <target names="indirect\\ reference\\ to\\ the\\ table\\ of\\ contents" refid="table-of-contents">
<section ids="section" names="section">
<title refid="toc-entry-1">
Section
@@ -1122,22 +1265,25 @@
Title
-----
-Let's reference it (`explicit target`_) to avoid an irrelevant error.
+References to the section (title_) use the ID from the `explicit target`_.
""",
"""\
<document source="test data">
<target refid="explicit-target">
- <section ids="title explicit-target" names="title explicit\\ target">
+ <section ids="explicit-target" names="title explicit\\ target">
<title>
Title
<paragraph>
- Let's reference it (
+ References to the section (
<reference refid="explicit-target">
+ title
+ ) use the ID from the \n\
+ <reference refid="explicit-target">
explicit target
- ) to avoid an irrelevant error.
+ .
"""],
["""\
-target1_ should refer to target2_, not the Title.
+target1_ should be an alias of target2_, not the Title.
.. _target1:
.. _target2: URI
@@ -1150,185 +1296,274 @@
<paragraph>
<reference refuri="URI">
target1
- should refer to \n\
+ should be an alias of \n\
<reference refuri="URI">
target2
, not the Title.
<target refid="target1">
- <target ids="target2 target1" names="target2 target1" refuri="URI">
- <section ids="title" names="title">
+ <target ids="target1" names="target2 target1" refuri="URI">
+ <section names="title">
<title>
Title
"""],
["""\
-An explicit target _`foo` overrides a homonymous implicit target.
-
foo
---
+With legacy_ids = False, an explicit target _`foo` takes over the
+reference name and identifier of a homonymous implicit target.
+
The reference foo_ points to the explicit target.
+Referencing from an external document can be done
+using the matching fragment identifier "#foo".
""",
"""\
<document source="test data">
- <paragraph>
- An explicit target \n\
- <target ids="foo" names="foo">
- foo
- overrides a homonymous implicit target.
- <section dupnames="foo" ids="foo-1">
+ <section dupnames="foo">
<title>
foo
- <system_message backrefs="foo-1" level="1" line="4" source="test data" type="INFO">
+ <system_message backrefs="foo" level="1" line="5" source="test data" type="INFO">
<paragraph>
- Duplicate implicit target name: "foo".
+ Target name overrides implicit target name "foo".
<paragraph>
+ With legacy_ids = False, an explicit target \n\
+ <target ids="foo" names="foo">
+ foo
+ takes over the
+ reference name and identifier of a homonymous implicit target.
+ <paragraph>
The reference \n\
<reference refid="foo">
foo
points to the explicit target.
+ Referencing from an external document can be done
+ using the matching fragment identifier "#foo".
"""],
["""\
-foo
----
+.. _external hyperlink: http://uri
-If an implicit target precedes a homonymous explicit target _`foo`,
-the explicit target takes over the reference name but not the identifier.
+`External hyperlink`_ reference.
+""",
+"""\
+<document source="test data">
+ <target names="external\\ hyperlink" refuri="http://uri">
+ <paragraph>
+ <reference refuri="http://uri">
+ External hyperlink
+ reference.
+"""],
+["""\
+Duplicate external target_'s (different URIs):
-The reference foo_ points to the explicit target. However, referencing from
-an external document requires the non-obvious fragment identifier "#foo-1".
+.. _target: first
+
+.. _target: second
""",
"""\
<document source="test data">
- <section dupnames="foo" ids="foo">
- <title>
- foo
- <system_message backrefs="foo-1" level="1" line="5" source="test data" type="INFO">
- <paragraph>
- Target name overrides implicit target name "foo".
+ <paragraph>
+ Duplicate external \n\
+ <problematic ids="problematic-1" refid="system-message-1">
+ target_
+ 's (different URIs):
+ <target dupnames="target" refuri="first">
+ <system_message level="2" line="5" source="test data" type="WARNING">
<paragraph>
- If an implicit target precedes a homonymous explicit target \n\
- <target ids="foo-1" names="foo">
- foo
- ,
- the explicit target takes over the reference name but not the identifier.
+ Duplicate explicit target name: "target".
+ <target dupnames="target" refuri="second">
+ <system_message backrefs="problematic-1" ids="system-message-1" level="3" line="1" source="test data" type="ERROR">
<paragraph>
- The reference \n\
- <reference refid="foo-1">
- foo
- points to the explicit target. However, referencing from
- an external document requires the non-obvious fragment identifier "#foo-1".
+ Duplicate target name, cannot be used as a unique reference: "target".
"""],
-])
-
-totest['implicit hyperlinks'] = ({'legacy_ids': False}, [
["""\
-.. contents:: Table of Contents
-.. _indirect reference to the table of contents: `table of contents`_
+Duplicate external targets (different URIs) without reference:
-Section
-=======
+.. _target: first
-Testing an `indirect reference to the table of contents`_.
+.. _target: second
""",
"""\
<document source="test data">
- <topic classes="contents" ids="table-of-contents" names="table\\ of\\ contents">
- <title>
- Table of Contents
- <bullet_list>
- <list_item>
- <paragraph>
- <reference ids="toc-entry-1" refid="section">
- Section
- <target ids="indirect-reference-to-the-table-of-contents" names="indirect\\ reference\\ to\\ the\\ table\\ of\\ contents" refid="table-of-contents">
- <section ids="section" names="section">
- <title refid="toc-entry-1">
- Section
+ <paragraph>
+ Duplicate external targets (different URIs) without reference:
+ <target dupnames="target" refuri="first">
+ <system_message level="2" line="5" source="test data" type="WARNING">
<paragraph>
- Testing an \n\
- <reference refid="table-of-contents">
- indirect reference to the table of contents
- .
+ Duplicate explicit target name: "target".
+ <target dupnames="target" refuri="second">
"""],
["""\
-.. _explicit target:
+.. _chained:
+.. _external hyperlink: http://uri
-Title
------
-
-References to the section (title_) use the ID from the `explicit target`_.
+`External hyperlink`_ reference
+and a chained_ reference too.
""",
"""\
<document source="test data">
- <target refid="explicit-target">
- <section ids="explicit-target" names="title explicit\\ target">
- <title>
- Title
+ <target refid="chained">
+ <target ids="chained" names="external\\ hyperlink chained" refuri="http://uri">
+ <paragraph>
+ <reference refuri="http://uri">
+ External hyperlink
+ reference
+ and a \n\
+ <reference refuri="http://uri">
+ chained
+ reference too.
+"""],
+["""\
+.. _external hyperlink: http://uri
+.. _indirect target: `external hyperlink`_
+""",
+"""\
+<document source="test data">
+ <target names="external\\ hyperlink" refuri="http://uri">
+ <target names="indirect\\ target" refuri="http://uri">
+ <system_message level="1" line="2" source="test data" type="INFO">
<paragraph>
- References to the section (
- <reference refid="explicit-target">
- title
- ) use the ID from the \n\
- <reference refid="explicit-target">
- explicit target
- .
+ Hyperlink target "indirect target" is not referenced.
"""],
["""\
-target1_ should refer to target2_, not the Title.
+.. _external hyperlink: http://uri
+.. _indirect hyperlink: `external hyperlink`_
-.. _target1:
-.. _target2: URI
+`Indirect hyperlink`_ reference.
+""",
+"""\
+<document source="test data">
+ <target names="external\\ hyperlink" refuri="http://uri">
+ <target names="indirect\\ hyperlink" refuri="http://uri">
+ <paragraph>
+ <reference refuri="http://uri">
+ Indirect hyperlink
+ reference.
+"""],
+["""\
+.. _external hyperlink: http://uri
+.. _chained:
+.. _indirect hyperlink: `external hyperlink`_
-Title
-=====
+Chained_ `indirect hyperlink`_ reference.
""",
"""\
<document source="test data">
+ <target names="external\\ hyperlink" refuri="http://uri">
+ <target refuri="http://uri">
+ <target ids="chained" names="indirect\\ hyperlink chained" refuri="http://uri">
<paragraph>
- <reference refuri="URI">
- target1
- should refer to \n\
- <reference refuri="URI">
- target2
- , not the Title.
- <target refid="target1">
- <target ids="target2 target1" names="target2 target1" refuri="URI">
- <section names="title">
- <title>
- Title
+ <reference refuri="http://uri">
+ Chained
+ \n\
+ <reference refuri="http://uri">
+ indirect hyperlink
+ reference.
"""],
["""\
-foo
----
+.. _external: http://uri
+.. _indirect: external_
+.. _internal:
-With legacy_ids = False, an explicit target _`foo` takes over the
-reference name and identifier of a homonymous implicit target.
+.. image:: picture.png
+ :target: external_
-The reference foo_ points to the explicit target.
-Referencing from an external document can be done
-using the matching fragment identifier "#foo".
+.. image:: picture.png
+ :target: indirect_
+
+.. image:: picture.png
+ :target: internal_
""",
"""\
<document source="test data">
- <section dupnames="foo">
- <title>
- foo
- <system_message backrefs="foo" level="1" line="5" source="test data" type="INFO">
- <paragraph>
- Target name overrides implicit target name "foo".
+ <target names="external" refuri="http://uri">
+ <target names="indirect" refuri="http://uri">
+ <target refid="internal">
+ <reference ids="internal" names="internal" refuri="http://uri">
+ <image uri="picture.png">
+ <reference refuri="http://uri">
+ <image uri="picture.png">
+ <reference refid="internal">
+ <image uri="picture.png">
+"""],
+["""\
+.. __: http://full
+__
+__ http://simplified
+.. _external: http://indirect.external
+__ external_
+__
+
+`Full syntax anonymous external hyperlink reference`__,
+`chained anonymous external reference`__,
+`simplified syntax anonymous external hyperlink reference`__,
+`indirect anonymous hyperlink reference`__,
+`internal anonymous hyperlink reference`__.
+""",
+"""\
+<document source="test data">
+ <target anonymous="1" refuri="http://full">
+ <target anonymous="1" refid="target-1">
+ <target anonymous="1" ids="target-1" refuri="http://simplified">
+ <target names="external" refuri="http://indirect.external">
+ <target anonymous="1" refuri="http://indirect.external">
+ <target anonymous="1" refid="target-2">
+ <paragraph ids="target-...
[truncated message content] |