From f3b2eab157e28d304906a4b5b48ff4b6a02342f2 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 20 Oct 2017 20:53:47 +0000 Subject: Fix bug #331: fixed the "trim" options of the "unicode" directive. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8188 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 4 +++ docutils/RELEASE-NOTES.txt | 2 ++ docutils/docutils/transforms/references.py | 6 ++-- .../expected/standalone_rst_docutils_xml.xml | 33 ++++++++++-------- .../expected/standalone_rst_html4css1.html | 12 ++++--- .../functional/expected/standalone_rst_html5.html | 12 ++++--- .../functional/expected/standalone_rst_latex.tex | 13 ++++--- .../expected/standalone_rst_pseudoxml.txt | 40 ++++++++++++++-------- .../functional/expected/standalone_rst_xetex.tex | 13 ++++--- docutils/test/functional/input/data/standard.txt | 8 ++++- 10 files changed, 89 insertions(+), 54 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 171eb17ba..81ba6d332 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -42,6 +42,10 @@ Changes Since 0.14 - Add field name as class argument to generic docinfo fields unconditionally. +* docutils/transforms/references.py + + - Fix bug #331: fixed the "trim" options of the "unicode" directive. + * docutils/writers/html5_polyglot/ - automatically add HTML5-compatible meta tags for docinfo items diff --git a/docutils/RELEASE-NOTES.txt b/docutils/RELEASE-NOTES.txt index c851c7ede..f2cf3b122 100644 --- a/docutils/RELEASE-NOTES.txt +++ b/docutils/RELEASE-NOTES.txt @@ -54,6 +54,8 @@ Release 0.15b.dev - Allow embedded colons in field list field names (before, tokens like ``:this:example:`` were considered ordinary text). + - Fixed a bug with the "trim" options of the "unicode" directive. + Release 0.14 (2017-08-03) ========================= diff --git a/docutils/docutils/transforms/references.py b/docutils/docutils/transforms/references.py index 5e9ea9686..cadf9d6da 100644 --- a/docutils/docutils/transforms/references.py +++ b/docutils/docutils/transforms/references.py @@ -692,14 +692,12 @@ class Substitutions(Transform): or 'trim' in subdef.attributes): if index > 0 and isinstance(parent[index - 1], nodes.Text): - parent.replace(parent[index - 1], - parent[index - 1].rstrip()) + parent[index - 1] = parent[index - 1].rstrip() if ('rtrim' in subdef.attributes or 'trim' in subdef.attributes): if (len(parent) > index + 1 and isinstance(parent[index + 1], nodes.Text)): - parent.replace(parent[index + 1], - parent[index + 1].lstrip()) + parent[index + 1] = parent[index + 1].lstrip() subdef_copy = subdef.deepcopy() try: # Take care of nested substitution references: diff --git a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml index 3d33fc95f..80cca7929 100644 --- a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml +++ b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml @@ -236,7 +236,8 @@ They are transformed from section titles after parsing. references 5 (a second reference 7), footnote references (manually numbered 1, anonymous auto-numbered 3, labeled auto-numbered 2, or symbolic *), citation references (CIT2002), - substitution references (EXAMPLE), and inline hyperlink targets + substitution references (EXAMPLE & + a trimmed heart (U+2665):♥), and inline hyperlink targets (see Targets below for a reference back to here). Character-level inline markup is also possible (although exceedingly ugly!) in reStructuredText. Problems are indicated by |problematic| text (generated by processing errors; this one is intentional). Here is a @@ -738,7 +739,7 @@ Python-specific usage examples; begun with ">>>"
<generated classes="sectnum">2.13.2   </generated>Duplicate Target Names - + Duplicate implicit target name: "duplicate target names". Since there are two "Duplicate Target Names" section headers, we @@ -1343,6 +1344,8 @@ footnotes 1, 2.15   Substitution Definitions An inline image (EXAMPLE) example: EXAMPLE + A Unicode example: + (Substitution definitions are not visible in the HTML source.)
@@ -1709,43 +1712,43 @@ 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". - + Hyperlink target "target" is not referenced. - + Hyperlink target "another-target" is not referenced. - + Hyperlink target "image-target-1" is not referenced. - + Hyperlink target "image-target-2" is not referenced. - + Hyperlink target "image-target-3" is not referenced. - + Hyperlink target "target1" is not referenced. - + Hyperlink target "target2" is not referenced. - + Hyperlink target "docutils" is not referenced. - + Hyperlink target "hyperlink targets" is not referenced.
diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index 4d66cff28..8e1229b98 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/test/functional/expected/standalone_rst_html4css1.html @@ -176,7 +176,8 @@ cross-references (example), ex references [5] (a second reference [7]), footnote references (manually numbered [1], anonymous auto-numbered [3], labeled auto-numbered [2], or symbolic [*]), citation references ([CIT2002]), -substitution references (EXAMPLE), and inline hyperlink targets +substitution references (EXAMPLE & +a trimmed heart (U+2665):♥), and inline hyperlink targets (see Targets below for a reference back to here). Character-level inline markup is also possible (although exceedingly ugly!) in reStructuredText. Problems are indicated by |problematic| text (generated by processing errors; this one is intentional). Here is a @@ -1019,6 +1020,7 @@ as a code block, here the rst file header_footer.tx

2.15   Substitution Definitions

An inline image (EXAMPLE) example:

+

A Unicode example:

(Substitution definitions are not visible in the HTML source.)

@@ -1365,16 +1367,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 392); 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 401); 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 428); 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 441); 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 2419ab67f..a3dd7a08e 100644 --- a/docutils/test/functional/expected/standalone_rst_html5.html +++ b/docutils/test/functional/expected/standalone_rst_html5.html @@ -194,7 +194,8 @@ cross-references (example), ex references 5 (a second reference 9), footnote references (manually numbered 1, anonymous auto-numbered 3, labeled auto-numbered 2, or symbolic *), citation references ([CIT2002]), -substitution references (EXAMPLE), and inline hyperlink targets +substitution references (EXAMPLE & +a trimmed heart (U+2665):♥), and inline hyperlink targets (see Targets below for a reference back to here). Character-level inline markup is also possible (although exceedingly ugly!) in reStructuredText. Problems are indicated by |problematic| text (generated by processing errors; this one is intentional). Here is a @@ -989,6 +990,7 @@ as a code block, here the rst file header_footer.

2.15 Substitution Definitions

An inline image (EXAMPLE) example:

+

A Unicode example:

(Substitution definitions are not visible in the HTML source.)

@@ -1546,19 +1548,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 392); 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 401); 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 428); 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 441); 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 b35b5f04f..46467fe48 100644 --- a/docutils/test/functional/expected/standalone_rst_latex.tex +++ b/docutils/test/functional/expected/standalone_rst_latex.tex @@ -347,7 +347,8 @@ cross-references (\hyperref[example]{example}), external hyperlinks with embedde (\href{http://www.python.org}{Python web site}), \href{http://www.python.org/}{anonymous hyperlink references}\DUfootnotemark{id38}{id29}{5} (\href{http://docutils.sourceforge.net/}{a second reference}\DUfootnotemark{id40}{id39}{8}), footnote references (manually numbered\DUfootnotemark{id1}{id8}{1}, anonymous auto-numbered\DUfootnotemark{id2}{id12}{3}, labeled auto-numbered\DUfootnotemark{id3}{label}{2}, or symbolic\DUfootnotemark{id4}{id13}{*}), citation references (\hyperlink{cit2002}{[CIT2002]}), -substitution references (\includegraphics{../../../docs/user/rst/images/biohazard.png}), and % +substitution references (\includegraphics{../../../docs/user/rst/images/biohazard.png} \& +a \emph{trimmed heart} \texttt{(U+2665):}\ding{170}), and % \phantomsection\label{inline-hyperlink-targets}inline hyperlink targets (see \hyperref[targets]{Targets} below for a reference back to here). Character-level inline markup is also possible (although exceedingly ugly!) in \emph{re}\texttt{Structured}\emph{Text}. Problems are indicated by % @@ -1480,6 +1481,8 @@ as a code block, here the rst file \texttt{header\_footer.txt} with line numbers An inline image (\includegraphics{../../../docs/user/rst/images/biohazard.png}) example: +A Unicode example: + (Substitution definitions are not visible in the HTML source.) @@ -2876,7 +2879,7 @@ Undefined substitution referenced: \textquotedbl{}problematic\textquotedbl{}. \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id45}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~391 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~392 \hyperlink{id17}{ Unknown target name: \textquotedbl{}5\textquotedbl{}. @@ -2886,7 +2889,7 @@ Unknown target name: \textquotedbl{}5\textquotedbl{}. \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id46}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~400 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~401 \hyperlink{id19}{ Unknown target name: \textquotedbl{}nonexistent\textquotedbl{}. @@ -2896,7 +2899,7 @@ Unknown target name: \textquotedbl{}nonexistent\textquotedbl{}. \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id47}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~427 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~428 \hyperlink{id48}{ Unknown target name: \textquotedbl{}hyperlink reference without a target\textquotedbl{}. @@ -2906,7 +2909,7 @@ Unknown target name: \textquotedbl{}hyperlink reference without a target\textquo \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id49}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~440 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~441 \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 4703f481c..a6887ef4f 100644 --- a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt +++ b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt @@ -450,6 +450,14 @@ ), substitution references ( EXAMPLE + & + a + + trimmed heart + + + (U+2665): + ♥ ), and inline hyperlink targets @@ -1132,7 +1140,7 @@ 2.13.2    Duplicate Target Names - + Duplicate implicit target name: "duplicate target names". @@ -1943,6 +1951,10 @@ ) example: EXAMPLE + + A Unicode example: + + ♥ (Substitution definitions are not visible in the HTML source.)
@@ -2307,42 +2319,42 @@ 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". - + Hyperlink target "target" is not referenced. - + Hyperlink target "another-target" is not referenced. - + Hyperlink target "image-target-1" is not referenced. - + Hyperlink target "image-target-2" is not referenced. - + Hyperlink target "image-target-3" is not referenced. - + Hyperlink target "target1" is not referenced. - + Hyperlink target "target2" is not referenced. - + Hyperlink target "docutils" is not referenced. - + Hyperlink target "hyperlink targets" is not referenced. diff --git a/docutils/test/functional/expected/standalone_rst_xetex.tex b/docutils/test/functional/expected/standalone_rst_xetex.tex index 3f8e9f1b6..7a50bb290 100644 --- a/docutils/test/functional/expected/standalone_rst_xetex.tex +++ b/docutils/test/functional/expected/standalone_rst_xetex.tex @@ -349,7 +349,8 @@ cross-references (\hyperref[example]{example}), external hyperlinks with embedde (\href{http://www.python.org}{Python web site}), \href{http://www.python.org/}{anonymous hyperlink references}\DUfootnotemark{id40}{id29}{5} (\href{http://docutils.sourceforge.net/}{a second reference}\DUfootnotemark{id42}{id41}{9}), footnote references (manually numbered\DUfootnotemark{id1}{id8}{1}, anonymous auto-numbered\DUfootnotemark{id2}{id12}{3}, labeled auto-numbered\DUfootnotemark{id3}{label}{2}, or symbolic\DUfootnotemark{id4}{id13}{*}), citation references (\hyperlink{cit2002}{[CIT2002]}), -substitution references (\includegraphics{../../../docs/user/rst/images/biohazard.png}), and % +substitution references (\includegraphics{../../../docs/user/rst/images/biohazard.png} \& +a \emph{trimmed heart} \texttt{(U+2665):}♥), and % \phantomsection\label{inline-hyperlink-targets}inline hyperlink targets (see \hyperref[targets]{Targets} below for a reference back to here). Character-level inline markup is also possible (although exceedingly ugly!) in \emph{re}\texttt{Structured}\emph{Text}. Problems are indicated by % @@ -1486,6 +1487,8 @@ as a code block, here the rst file \texttt{header\_footer.txt} with line numbers An inline image (\includegraphics{../../../docs/user/rst/images/biohazard.png}) example: +A Unicode example: + (Substitution definitions are not visible in the HTML source.) @@ -2894,7 +2897,7 @@ Undefined substitution referenced: \textquotedbl{}problematic\textquotedbl{}. \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id47}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~391 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~392 \hyperlink{id17}{ Unknown target name: \textquotedbl{}5\textquotedbl{}. @@ -2904,7 +2907,7 @@ Unknown target name: \textquotedbl{}5\textquotedbl{}. \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id48}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~400 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~401 \hyperlink{id19}{ Unknown target name: \textquotedbl{}nonexistent\textquotedbl{}. @@ -2914,7 +2917,7 @@ Unknown target name: \textquotedbl{}nonexistent\textquotedbl{}. \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id49}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~427 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~428 \hyperlink{id50}{ Unknown target name: \textquotedbl{}hyperlink reference without a target\textquotedbl{}. @@ -2924,7 +2927,7 @@ Unknown target name: \textquotedbl{}hyperlink reference without a target\textquo \DUtitle[system-message]{system-message} \raisebox{1em}{\hypertarget{id51}{}} -{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~440 +{\color{red}ERROR/3} in \texttt{functional/input/data/standard.txt}, line~441 \hyperlink{id52}{ Duplicate target name, cannot be used as a unique reference: \textquotedbl{}duplicate target names\textquotedbl{}. diff --git a/docutils/test/functional/input/data/standard.txt b/docutils/test/functional/input/data/standard.txt index 7e2b1d7f3..8bd1d99f0 100644 --- a/docutils/test/functional/input/data/standard.txt +++ b/docutils/test/functional/input/data/standard.txt @@ -109,7 +109,8 @@ cross-references (example_), external hyperlinks with embedded URIs references`__ (`a second reference`__), footnote references (manually numbered [1]_, anonymous auto-numbered [#]_, labeled auto-numbered [#label]_, or symbolic [*]_), citation references ([CIT2002]_), -substitution references (|example|), and _`inline hyperlink targets` +substitution references (|example| & +a *trimmed heart* ``(U+2665):`` |heart|), and _`inline hyperlink targets` (see Targets_ below for a reference back to here). Character-level inline markup is also possible (although exceedingly ugly!) in *re*\ ``Structured``\ *Text*. Problems are indicated by |problematic| text @@ -906,6 +907,11 @@ An inline image (|example|) example: .. |EXAMPLE| image:: ../../../docs/user/rst/images/biohazard.png +A Unicode example: + +.. |heart| unicode:: 0x2665 + :trim: + (Substitution definitions are not visible in the HTML source.) Comments -- cgit v1.2.1