From a68383266f390971f59dd220e3027afec43f2290 Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 6 Apr 2017 13:10:34 +0000 Subject: [PATCH] Do not add a second ID to problematic references. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8055 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 4 ++++ docutils/docutils/transforms/references.py | 5 ++++- .../expected/standalone_rst_docutils_xml.xml | 16 ++++++++-------- .../expected/standalone_rst_html4css1.html | 22 +++++++++++----------- .../functional/expected/standalone_rst_html5.html | 22 +++++++++++----------- .../functional/expected/standalone_rst_latex.tex | 22 ++++++++++------------ .../expected/standalone_rst_pseudoxml.txt | 16 ++++++++-------- .../functional/expected/standalone_rst_xetex.tex | 22 ++++++++++------------ docutils/test/test_transforms/test_hyperlinks.py | 4 ++-- 9 files changed, 68 insertions(+), 65 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 02f41fd23..541bb0cb9 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -49,6 +49,10 @@ Changes Since 0.13.1 - Rework patch [ 120 ] (revert change to ``Table.get_column_widths()`` that led to problems in an application with a custom table directive). +* docutils/transforms/references.py + + - Don't add a second ID to problematic references. + * docutils/utils/__init__.py: - Added ``split_escaped_whitespace`` function, support for escaped diff --git a/docutils/docutils/transforms/references.py b/docutils/docutils/transforms/references.py index 25c3e72f2..0642a634a 100644 --- a/docutils/docutils/transforms/references.py +++ b/docutils/docutils/transforms/references.py @@ -893,7 +893,10 @@ class DanglingReferencesVisitor(nodes.SparseNodeVisitor): msgid = self.document.set_id(msg) prb = nodes.problematic( node.rawsource, node.rawsource, refid=msgid) - prbid = self.document.set_id(prb) + try: + prbid = node['ids'][0] + except IndexError: + prbid = self.document.set_id(prb) msg.add_backref(prbid) node.replace_self(prb) else: diff --git a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml index 9c26d2335..1b57754f5 100644 --- a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml +++ b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml @@ -700,7 +700,7 @@ Python-specific usage examples; begun with ">>>" Here's an unreferenced footnote, with a reference to a - nonexistent footnote: [5]_. + nonexistent footnote: [5]_.
@@ -710,7 +710,7 @@ Python-specific usage examples; begun with ">>>" Citations are text-labeled footnotes. They may be rendered separately and differently from footnotes. - Here's a reference to the above, CIT2002, and a [nonexistent]_ + Here's a reference to the above, CIT2002, and a [nonexistent]_ citation.
@@ -728,7 +728,7 @@ Python-specific usage examples; begun with ">>>" Targets may be indirect and anonymous. Thus this phrase may also refer to the Targets section. - Here's a `hyperlink reference without a target`_, which generates an + Here's a `hyperlink reference without a target`_, which generates an error.
<generated classes="sectnum">2.13.1   </generated>Duplicate Target Names @@ -743,7 +743,7 @@ Python-specific usage examples; begun with ">>>" Since there are two "Duplicate Target Names" section headers, we cannot uniquely refer to either of them by name. If we try to (like - this: `Duplicate Target Names`_), an error is generated. + this: `Duplicate Target Names`_), an error is generated.
@@ -1709,16 +1709,16 @@ Comments may contain non-ASCII characters: ä ö ü æ ø å Undefined substitution referenced: "problematic". - + Unknown target name: "5". - + Unknown target name: "nonexistent". - + Unknown target name: "hyperlink reference without a target". - + Duplicate target name, cannot be used as a unique reference: "duplicate target names". diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index 53e7a9de5..115c2d2fd 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/test/functional/expected/standalone_rst_html4css1.html @@ -506,7 +506,7 @@ Here's a reference to the next footnote: [4]Here's an unreferenced footnote, with a reference to a -nonexistent footnote: [5]_. +nonexistent footnote: [5]_. @@ -519,7 +519,7 @@ nonexistent footnote: -

Here's a reference to the above, [CIT2002], and a [nonexistent]_ +

Here's a reference to the above, [CIT2002], and a [nonexistent]_ citation.

@@ -533,7 +533,7 @@ hyperlink targets are also possible.

"Python [5]".

Targets may be indirect and anonymous. Thus this phrase may also refer to the Targets section.

-

Here's a `hyperlink reference without a target`_, which generates an +

Here's a `hyperlink reference without a target`_, which generates an error.

2.13.1   Duplicate Target Names

@@ -545,7 +545,7 @@ explicit targets will generate "warning" (level-2) system messages.

2.13.2   Duplicate Target Names

Since there are two "Duplicate Target Names" section headers, we cannot uniquely refer to either of them by name. If we try to (like -this: `Duplicate Target Names`_), an error is generated.

+this: `Duplicate Target Names`_), an error is generated.

@@ -1369,16 +1369,16 @@ section, "Docutils System Messages":

System Message: ERROR/3 (functional/input/data/standard.txt, line 104); backlink

Undefined substitution referenced: "problematic".
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 391); backlink

+

System Message: ERROR/3 (functional/input/data/standard.txt, line 391); backlink

Unknown target name: "5".
-
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 400); backlink

+
+

System Message: ERROR/3 (functional/input/data/standard.txt, line 400); backlink

Unknown target name: "nonexistent".
-
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 427); backlink

+
+

System Message: ERROR/3 (functional/input/data/standard.txt, line 427); backlink

Unknown target name: "hyperlink reference without a target".
-
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 440); backlink

+
+

System Message: ERROR/3 (functional/input/data/standard.txt, line 440); backlink

Duplicate target name, cannot be used as a unique reference: "duplicate target names".
diff --git a/docutils/test/functional/expected/standalone_rst_html5.html b/docutils/test/functional/expected/standalone_rst_html5.html index ee9e71679..b75483e64 100644 --- a/docutils/test/functional/expected/standalone_rst_html5.html +++ b/docutils/test/functional/expected/standalone_rst_html5.html @@ -489,7 +489,7 @@ Here's a reference to the next footnote:
4

Here's an unreferenced footnote, with a reference to a -nonexistent footnote: [5]_.

+nonexistent footnote: [5]_.

@@ -501,7 +501,7 @@ nonexistent footnote: -

Here's a reference to the above, [CIT2002], and a [nonexistent]_ +

Here's a reference to the above, [CIT2002], and a [nonexistent]_ citation.

@@ -515,7 +515,7 @@ hyperlink targets are also possible.

"Python 5".

Targets may be indirect and anonymous. Thus this phrase may also refer to the Targets section.

-

Here's a `hyperlink reference without a target`_, which generates an +

Here's a `hyperlink reference without a target`_, which generates an error.

2.13.1 Duplicate Target Names

@@ -527,7 +527,7 @@ explicit targets will generate "warning" (level-2) system messages.

2.13.2 Duplicate Target Names

Since there are two "Duplicate Target Names" section headers, we cannot uniquely refer to either of them by name. If we try to (like -this: `Duplicate Target Names`_), an error is generated.

+this: `Duplicate Target Names`_), an error is generated.

@@ -1544,19 +1544,19 @@ section, "Docutils System Messages":

Undefined substitution referenced: "problematic".

-

System Message: ERROR/3 (functional/input/data/standard.txt, line 391); backlink

+

System Message: ERROR/3 (functional/input/data/standard.txt, line 391); backlink

Unknown target name: "5".

-
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 400); backlink

+
+

System Message: ERROR/3 (functional/input/data/standard.txt, line 400); backlink

Unknown target name: "nonexistent".

-
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 427); backlink

+
+

System Message: ERROR/3 (functional/input/data/standard.txt, line 427); backlink

Unknown target name: "hyperlink reference without a target".

-
-

System Message: ERROR/3 (functional/input/data/standard.txt, line 440); backlink

+
+

System Message: ERROR/3 (functional/input/data/standard.txt, line 440); backlink

Duplicate target name, cannot be used as a unique reference: "duplicate target names".

diff --git a/docutils/test/functional/expected/standalone_rst_latex.tex b/docutils/test/functional/expected/standalone_rst_latex.tex index 73b4a5623..16af31e16 100644 --- a/docutils/test/functional/expected/standalone_rst_latex.tex +++ b/docutils/test/functional/expected/standalone_rst_latex.tex @@ -751,7 +751,6 @@ This footnote shows the next symbol in the sequence. \DUfootnotetext{id16}{id16}{4}{% Here’s an unreferenced footnote, with a reference to a nonexistent footnote:% -\raisebox{1em}{\hypertarget{id46}{}}% \raisebox{1em}{\hypertarget{id17}{}}\hyperlink{id45}{\textbf{\color{red}{[}5{]}\_}}. } @@ -765,8 +764,7 @@ rendered separately and differently from footnotes. \end{figure} Here’s a reference to the above, \hyperlink{cit2002}{[CIT2002]}, and a % -\raisebox{1em}{\hypertarget{id48}{}}% -\raisebox{1em}{\hypertarget{id19}{}}\hyperlink{id47}{\textbf{\color{red}{[}nonexistent{]}\_}} +\raisebox{1em}{\hypertarget{id19}{}}\hyperlink{id46}{\textbf{\color{red}{[}nonexistent{]}\_}} citation. @@ -790,7 +788,7 @@ Targets may be indirect and anonymous. Thus \hyperref[targets]{this phrase} may refer to the \hyperref[targets]{Targets} section. Here’s a % -\raisebox{1em}{\hypertarget{id50}{}}\hyperlink{id49}{\textbf{\color{red}`hyperlink reference without a target`\_}}, which generates an +\raisebox{1em}{\hypertarget{id48}{}}\hyperlink{id47}{\textbf{\color{red}`hyperlink reference without a target`\_}}, which generates an error. @@ -810,7 +808,7 @@ explicit targets will generate “warning” (level-2) system messages. Since there are two “Duplicate Target Names” section headers, we cannot uniquely refer to either of them by name. If we try to (like this: % -\raisebox{1em}{\hypertarget{id52}{}}\hyperlink{id51}{\textbf{\color{red}`Duplicate Target Names`\_}}), an error is generated. +\raisebox{1em}{\hypertarget{id50}{}}\hyperlink{id49}{\textbf{\color{red}`Duplicate Target Names`\_}}), an error is generated. \subsection{2.14~~~Directives% @@ -2811,37 +2809,37 @@ Undefined substitution referenced: \textquotedbl{}problematic\textquotedbl{}. {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~391 -\hyperlink{id46}{ +\hyperlink{id17}{ Unknown target name: \textquotedbl{}5\textquotedbl{}. }} \DUadmonition[system-message]{ \DUtitle[system-message]{system-message} -\raisebox{1em}{\hypertarget{id47}{}} +\raisebox{1em}{\hypertarget{id46}{}} {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~400 -\hyperlink{id48}{ +\hyperlink{id19}{ Unknown target name: \textquotedbl{}nonexistent\textquotedbl{}. }} \DUadmonition[system-message]{ \DUtitle[system-message]{system-message} -\raisebox{1em}{\hypertarget{id49}{}} +\raisebox{1em}{\hypertarget{id47}{}} {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~427 -\hyperlink{id50}{ +\hyperlink{id48}{ Unknown target name: \textquotedbl{}hyperlink reference without a target\textquotedbl{}. }} \DUadmonition[system-message]{ \DUtitle[system-message]{system-message} -\raisebox{1em}{\hypertarget{id51}{}} +\raisebox{1em}{\hypertarget{id49}{}} {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~440 -\hyperlink{id52}{ +\hyperlink{id50}{ Duplicate target name, cannot be used as a unique reference: \textquotedbl{}duplicate target names\textquotedbl{}. }} diff --git a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt index 5e06805ab..05729143a 100644 --- a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt +++ b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt @@ -1044,7 +1044,7 @@ Here's an unreferenced footnote, with a reference to a nonexistent footnote: - + [5]_ .
@@ -1063,7 +1063,7 @@ CIT2002 , and a - + [nonexistent]_ citation. @@ -1114,7 +1114,7 @@ Here's a - + `hyperlink reference without a target`_ , which generates an error. @@ -1139,7 +1139,7 @@ Since there are two "Duplicate Target Names" section headers, we cannot uniquely refer to either of them by name. If we try to (like this: - + `Duplicate Target Names`_ ), an error is generated.
@@ -2307,16 +2307,16 @@ Undefined substitution referenced: "problematic". - + Unknown target name: "5". - + Unknown target name: "nonexistent". - + Unknown target name: "hyperlink reference without a target". - + Duplicate target name, cannot be used as a unique reference: "duplicate target names". diff --git a/docutils/test/functional/expected/standalone_rst_xetex.tex b/docutils/test/functional/expected/standalone_rst_xetex.tex index bfffb36a6..058c20e5c 100644 --- a/docutils/test/functional/expected/standalone_rst_xetex.tex +++ b/docutils/test/functional/expected/standalone_rst_xetex.tex @@ -756,7 +756,6 @@ This footnote shows the next symbol in the sequence. \DUfootnotetext{id16}{id16}{4}{% Here’s an unreferenced footnote, with a reference to a nonexistent footnote:% -\raisebox{1em}{\hypertarget{id48}{}}% \raisebox{1em}{\hypertarget{id17}{}}\hyperlink{id47}{\textbf{\color{red}{[}5{]}\_}}. } @@ -770,8 +769,7 @@ rendered separately and differently from footnotes. \end{figure} Here’s a reference to the above, \hyperlink{cit2002}{[CIT2002]}, and a % -\raisebox{1em}{\hypertarget{id50}{}}% -\raisebox{1em}{\hypertarget{id19}{}}\hyperlink{id49}{\textbf{\color{red}{[}nonexistent{]}\_}} +\raisebox{1em}{\hypertarget{id19}{}}\hyperlink{id48}{\textbf{\color{red}{[}nonexistent{]}\_}} citation. @@ -795,7 +793,7 @@ Targets may be indirect and anonymous. Thus \hyperref[targets]{this phrase} may refer to the \hyperref[targets]{Targets} section. Here’s a % -\raisebox{1em}{\hypertarget{id52}{}}\hyperlink{id51}{\textbf{\color{red}`hyperlink reference without a target`\_}}, which generates an +\raisebox{1em}{\hypertarget{id50}{}}\hyperlink{id49}{\textbf{\color{red}`hyperlink reference without a target`\_}}, which generates an error. @@ -815,7 +813,7 @@ explicit targets will generate “warning” (level-2) system messages. Since there are two “Duplicate Target Names” section headers, we cannot uniquely refer to either of them by name. If we try to (like this: % -\raisebox{1em}{\hypertarget{id54}{}}\hyperlink{id53}{\textbf{\color{red}`Duplicate Target Names`\_}}), an error is generated. +\raisebox{1em}{\hypertarget{id52}{}}\hyperlink{id51}{\textbf{\color{red}`Duplicate Target Names`\_}}), an error is generated. \subsection{2.14   Directives% @@ -2832,37 +2830,37 @@ Undefined substitution referenced: \textquotedbl{}problematic\textquotedbl{}. {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~391 -\hyperlink{id48}{ +\hyperlink{id17}{ Unknown target name: \textquotedbl{}5\textquotedbl{}. }} \DUadmonition[system-message]{ \DUtitle[system-message]{system-message} -\raisebox{1em}{\hypertarget{id49}{}} +\raisebox{1em}{\hypertarget{id48}{}} {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~400 -\hyperlink{id50}{ +\hyperlink{id19}{ Unknown target name: \textquotedbl{}nonexistent\textquotedbl{}. }} \DUadmonition[system-message]{ \DUtitle[system-message]{system-message} -\raisebox{1em}{\hypertarget{id51}{}} +\raisebox{1em}{\hypertarget{id49}{}} {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~427 -\hyperlink{id52}{ +\hyperlink{id50}{ Unknown target name: \textquotedbl{}hyperlink reference without a target\textquotedbl{}. }} \DUadmonition[system-message]{ \DUtitle[system-message]{system-message} -\raisebox{1em}{\hypertarget{id53}{}} +\raisebox{1em}{\hypertarget{id51}{}} {\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~440 -\hyperlink{id54}{ +\hyperlink{id52}{ Duplicate target name, cannot be used as a unique reference: \textquotedbl{}duplicate target names\textquotedbl{}. }} diff --git a/docutils/test/test_transforms/test_hyperlinks.py b/docutils/test/test_transforms/test_hyperlinks.py index 2245e7245..35f17c8e7 100755 --- a/docutils/test/test_transforms/test_hyperlinks.py +++ b/docutils/test/test_transforms/test_hyperlinks.py @@ -912,7 +912,7 @@ Duplicate manual footnote labels, with reference ([1]_): Duplicate manual footnote labels, with reference ( - + [1]_ ): @@ -928,7 +928,7 @@ Duplicate manual footnote labels, with reference ([1]_): Duplicate explicit target name: "1". Footnote. - + Duplicate target name, cannot be used as a unique reference: "1". """], -- 2.11.4.GIT