From 76cbb4bea33bfcc00fbfd9f8bb2419953a1aaa6d Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 27 Feb 2005 01:00:59 +0000 Subject: when relocating a target, it now acquires the children of its new parent; fixed bug in recording internal targets so that anonymous targets are relocated as well git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@2996 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/docutils/parsers/rst/states.py | 2 + docutils/docutils/transforms/references.py | 5 +- .../expected/standalone_rst_html4css1.html | 6 +- .../functional/expected/standalone_rst_latex.tex | 6 +- docutils/test/test_transforms/test_hyperlinks.py | 68 +++++++++++----------- 5 files changed, 46 insertions(+), 41 deletions(-) diff --git a/docutils/docutils/parsers/rst/states.py b/docutils/docutils/parsers/rst/states.py index 3427c4694..f2c2d5144 100644 --- a/docutils/docutils/parsers/rst/states.py +++ b/docutils/docutils/parsers/rst/states.py @@ -1857,6 +1857,8 @@ class Body(RSTState): else: # anonymous target if refuri: target['refuri'] = refuri + else: + self.document.note_internal_target(target) target['anonymous'] = 1 self.document.note_anonymous_target(target) diff --git a/docutils/docutils/transforms/references.py b/docutils/docutils/transforms/references.py index 8fda16c77..c8989f2a6 100644 --- a/docutils/docutils/transforms/references.py +++ b/docutils/docutils/transforms/references.py @@ -448,7 +448,10 @@ class InternalTargets(Transform): element.walk(visitor) except nodes.NodeFound: target.parent.remove(target) - visitor.found.insert(0, target) + for child in visitor.found: + target += child + visitor.found.children = [] + visitor.found += target return else: # At end of section or container; try parent's sibling diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index b4e932b8d..c54bf046d 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/test/functional/expected/standalone_rst_html4css1.html @@ -211,7 +211,7 @@ live link to PEP 258 here.

-

2.3   Enumerated Lists

+

2.3   Enumerated Lists

  1. Arabic numerals.

      @@ -490,9 +490,9 @@ citation.

2.13   Targets

-

This paragraph is pointed to by the explicit "example" target. A +

This paragraph is pointed to by the explicit "example" target. A reference can be found under Inline Markup, above. Inline -hyperlink targets are also possible.

+hyperlink targets are also possible.

Section headers are implicit targets, referred to by name. See Targets, which is a subsection of Body Elements.

Explicit external targets are interpolated into references such as diff --git a/docutils/test/functional/expected/standalone_rst_latex.tex b/docutils/test/functional/expected/standalone_rst_latex.tex index 847e1749e..a65919472 100644 --- a/docutils/test/functional/expected/standalone_rst_latex.tex +++ b/docutils/test/functional/expected/standalone_rst_latex.tex @@ -374,7 +374,7 @@ This nested list should be compacted by the HTML writer. \hypertarget{enumerated-lists}{} \pdfbookmark[1]{2.3~~~Enumerated Lists}{enumerated-lists} -\subsection*{2.3~~~\hypertarget{target}{}Enumerated Lists} +\subsection*{2.3~~~\hypertarget{target}{Enumerated Lists}} \newcounter{listcnt1} \begin{list}{\arabic{listcnt1}.} { @@ -773,9 +773,9 @@ citation. \pdfbookmark[1]{2.13~~~Targets}{targets} \subsection*{2.13~~~Targets} -\hypertarget{example}{}This paragraph is pointed to by the explicit ``example'' target. A +\hypertarget{example}{This paragraph is pointed to by the explicit ``example'' target. A reference can be found under \href{\#inline-markup}{Inline Markup}, above. \href{\#inline-hyperlink-targets}{Inline -hyperlink targets} are also possible. +hyperlink targets} are also possible.} Section headers are implicit targets, referred to by name. See \href{\#targets}{Targets}, which is a subsection of \href{\#body-elements}{Body Elements}. diff --git a/docutils/test/test_transforms/test_hyperlinks.py b/docutils/test/test_transforms/test_hyperlinks.py index 3a09e0207..e82a3580d 100755 --- a/docutils/test/test_transforms/test_hyperlinks.py +++ b/docutils/test/test_transforms/test_hyperlinks.py @@ -68,9 +68,9 @@ direct_ internal - - direct - internal + + direct + internal """], ["""\ .. _ztarget: @@ -84,9 +84,9 @@ indirect_ internal - - indirect - internal + + indirect + internal """], @@ -226,10 +226,10 @@ __ """, """\ - - - direct internal + + + direct internal """], ["""\ .. _ztarget: @@ -242,8 +242,8 @@ __ ztarget_ - - indirect internal + + indirect internal """], ["""\ @@ -263,13 +263,13 @@ __ ztarget_ - First + First Duplicate explicit target name: "ztarget". - Second + Second `indirect internal`__ @@ -324,7 +324,7 @@ By this `internal hyperlink`_ referemce. - This paragraph referenced. + This paragraph referenced. By this \n\ @@ -346,8 +346,8 @@ The results of the transform are not visible at the XML level. - - This paragraph referenced. + + This paragraph referenced. By this \n\ @@ -461,23 +461,23 @@ __ - - - Full syntax anonymous external hyperlink reference - , - - chained anonymous external reference - , - - simplified syntax anonymous external hyperlink reference - , - - indirect anonymous hyperlink reference - , - - internal anonymous hyperlink reference - . + + + Full syntax anonymous external hyperlink reference + , + + chained anonymous external reference + , + + simplified syntax anonymous external hyperlink reference + , + + indirect anonymous hyperlink reference + , + + internal anonymous hyperlink reference + . """], ["""\ Duplicate external target_'s (different URIs): @@ -542,7 +542,7 @@ __ http://example.org - + @@ -594,7 +594,7 @@ Let's reference it (`explicit target`_) to avoid an irrelevant error.

<target id="explicit-target" name="explicit target"> - Title + Title <paragraph> Let's reference it ( <reference name="explicit target" refid="explicit-target"> -- cgit v1.2.1