|
From: <mi...@us...> - 2021-09-20 13:03:41
|
Revision: 8831
http://sourceforge.net/p/docutils/code/8831
Author: milde
Date: 2021-09-20 13:03:39 +0000 (Mon, 20 Sep 2021)
Log Message:
-----------
Skip system_messages when propagating targets. Fixes bug #425.
Testing with "alltests.py" is currently impossible due to
caching (see itest_hyperlinks_de.py)
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/transforms/references.py
trunk/docutils/test/test_transforms/test_hyperlinks.py
Added Paths:
-----------
trunk/docutils/test/test_transforms/itest_hyperlinks_de.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-09-20 13:03:28 UTC (rev 8830)
+++ trunk/docutils/HISTORY.txt 2021-09-20 13:03:39 UTC (rev 8831)
@@ -57,6 +57,10 @@
.. _LaTeX syntax for mathematics: docs/ref/rst/mathematics.html
+* docutils/transforms/references.py
+
+ - Skip system_messages when propagating targets. Fixes bug #425.
+
* docutils/utils/__init__.py
- Removed ``unique_combinations`` (obsoleted by ``itertools.combinations``).
@@ -109,13 +113,13 @@
- Apply patch #181 "Fix tocdepth when chapter/part in use" by
John Thorvald Wodder II.
-
+
- Fix newlines after/before ids_to_labels() (cf. patch #183).
- Refactor/revise ToC writing.
-
+
- Don't add ``\phantomsection`` to labels in math-blocks.
-
+
- Improve spacing and allow customization of Docutils-generated table
of contents.
Modified: trunk/docutils/docutils/transforms/references.py
===================================================================
--- trunk/docutils/docutils/transforms/references.py 2021-09-20 13:03:28 UTC (rev 8830)
+++ trunk/docutils/docutils/transforms/references.py 2021-09-20 13:03:39 UTC (rev 8831)
@@ -42,7 +42,7 @@
def apply(self):
for target in self.document.traverse(nodes.target):
- # Only block-level targets without reference (like ".. target:"):
+ # Only block-level targets without reference (like ".. _target:"):
if (isinstance(target.parent, nodes.TextElement) or
(target.hasattr('refid') or target.hasattr('refuri') or
target.hasattr('refname'))):
@@ -49,41 +49,44 @@
continue
assert len(target) == 0, 'error: block-level target has children'
next_node = target.next_node(ascend=True)
+ # skip system messages (may be removed by universal.FilterMessages)
+ while isinstance(next_node, nodes.system_message):
+ next_node = next_node.next_node(ascend=True, descend=False)
# Do not move names and ids into Invisibles (we'd lose the
# attributes) or different Targetables (e.g. footnotes).
- if (next_node is not None and
- ((not isinstance(next_node, nodes.Invisible) and
- not isinstance(next_node, nodes.Targetable)) or
- isinstance(next_node, nodes.target))):
- next_node['ids'].extend(target['ids'])
- next_node['names'].extend(target['names'])
- # Set defaults for next_node.expect_referenced_by_name/id.
- if not hasattr(next_node, 'expect_referenced_by_name'):
- next_node.expect_referenced_by_name = {}
- if not hasattr(next_node, 'expect_referenced_by_id'):
- next_node.expect_referenced_by_id = {}
- for id in target['ids']:
- # Update IDs to node mapping.
- self.document.ids[id] = next_node
- # If next_node is referenced by id ``id``, this
- # target shall be marked as referenced.
- next_node.expect_referenced_by_id[id] = target
- for name in target['names']:
- next_node.expect_referenced_by_name[name] = target
- # If there are any expect_referenced_by_... attributes
- # in target set, copy them to next_node.
- next_node.expect_referenced_by_name.update(
- getattr(target, 'expect_referenced_by_name', {}))
- next_node.expect_referenced_by_id.update(
- getattr(target, 'expect_referenced_by_id', {}))
- # Set refid to point to the first former ID of target
- # which is now an ID of next_node.
- target['refid'] = target['ids'][0]
- # Clear ids and names; they have been moved to
- # next_node.
- target['ids'] = []
- target['names'] = []
- self.document.note_refid(target)
+ if (next_node is None
+ or isinstance(next_node, (nodes.Invisible, nodes.Targetable))
+ and not isinstance(next_node, nodes.target)):
+ continue
+ next_node['ids'].extend(target['ids'])
+ next_node['names'].extend(target['names'])
+ # Set defaults for next_node.expect_referenced_by_name/id.
+ if not hasattr(next_node, 'expect_referenced_by_name'):
+ next_node.expect_referenced_by_name = {}
+ if not hasattr(next_node, 'expect_referenced_by_id'):
+ next_node.expect_referenced_by_id = {}
+ for id in target['ids']:
+ # Update IDs to node mapping.
+ self.document.ids[id] = next_node
+ # If next_node is referenced by id ``id``, this
+ # target shall be marked as referenced.
+ next_node.expect_referenced_by_id[id] = target
+ for name in target['names']:
+ next_node.expect_referenced_by_name[name] = target
+ # If there are any expect_referenced_by_... attributes
+ # in target set, copy them to next_node.
+ next_node.expect_referenced_by_name.update(
+ getattr(target, 'expect_referenced_by_name', {}))
+ next_node.expect_referenced_by_id.update(
+ getattr(target, 'expect_referenced_by_id', {}))
+ # Set refid to point to the first former ID of target
+ # which is now an ID of next_node.
+ target['refid'] = target['ids'][0]
+ # Clear ids and names; they have been moved to
+ # next_node.
+ target['ids'] = []
+ target['names'] = []
+ self.document.note_refid(target)
class AnonymousHyperlinks(Transform):
Added: trunk/docutils/test/test_transforms/itest_hyperlinks_de.py
===================================================================
--- trunk/docutils/test/test_transforms/itest_hyperlinks_de.py (rev 0)
+++ trunk/docutils/test/test_transforms/itest_hyperlinks_de.py 2021-09-20 13:03:39 UTC (rev 8831)
@@ -0,0 +1,76 @@
+#! /usr/bin/env python
+
+# $Id$
+# Author: David Goodger <go...@py...>
+# Copyright: This module has been placed in the public domain.
+
+"""
+Tests for docutils.transforms.references.Hyperlinks with non-English language.
+
+TODO: This test fails currently when run as part of "alltests" because
+
+ - the "info" system-messages for directive fallbacks are only generated
+ once (the name -> directive mapping is cached in
+ ``docutils.parsers.rst.directives._directives``).
+
+ - the cache is not reset between after processing a document
+ (i.e. it contains name -> directive mappings from other tests).
+
+ See also https://sourceforge.net/p/docutils/feature-requests/71/
+"""
+
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_transforms import DocutilsTestSupport
+from docutils.transforms.references import PropagateTargets, \
+ AnonymousHyperlinks, IndirectHyperlinks, ExternalTargets, \
+ InternalTargets, DanglingReferences
+from docutils.parsers.rst import Parser, directives
+
+def suite():
+ parser = Parser()
+ settings = {}
+ settings['language_code'] = 'de'
+ s = DocutilsTestSupport.TransformTestSuite(
+ parser, suite_settings=settings)
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['hyperlinks'] = ((PropagateTargets, AnonymousHyperlinks,
+ IndirectHyperlinks, ExternalTargets,
+ InternalTargets, DanglingReferences), [
+
+["""\
+Target_ should propagate past the system_message to set "id" on note.
+
+.. _target:
+.. note:: Kurznotiz
+ :name: mynote
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <reference name="Target" refid="target">
+ Target
+ should propagate past the system_message to set "id" on note.
+ <target refid="target">
+ <system_message level="1" line="4" source="test data" type="INFO">
+ <paragraph>
+ No directive entry for "note" in module "docutils.parsers.rst.languages.de".
+ Using English fallback for directive "note".
+ <note ids="mynote target" names="mynote target">
+ <paragraph>
+ Kurznotiz
+ <system_message level="1" source="test data" type="INFO">
+ <paragraph>
+ Using <module 'docutils.languages.de' from '/usr/local/src/docutils-git-svn/docutils/docutils/languages/de.pyc'> for language "de".
+"""],
+])
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_transforms/itest_hyperlinks_de.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Modified: trunk/docutils/test/test_transforms/test_hyperlinks.py
===================================================================
--- trunk/docutils/test/test_transforms/test_hyperlinks.py 2021-09-20 13:03:28 UTC (rev 8830)
+++ trunk/docutils/test/test_transforms/test_hyperlinks.py 2021-09-20 13:03:39 UTC (rev 8831)
@@ -30,9 +30,8 @@
# target/reference, direct/indirect, internal/external, and named/anonymous,
# plus embedded URIs.
totest['exhaustive_hyperlinks'] = ((PropagateTargets, AnonymousHyperlinks,
- IndirectHyperlinks,
- ExternalTargets, InternalTargets,
- DanglingReferences), [
+ IndirectHyperlinks, ExternalTargets,
+ InternalTargets, DanglingReferences), [
["""\
direct_ external
@@ -185,7 +184,7 @@
internal
<target ids="indirect" names="indirect" refname="implicit">
<paragraph>
- Direct internal reference:
+ Direct internal reference: \n\
<problematic ids="problematic-2" refid="system-message-2">
Implicit_
<system_message backrefs="problematic-1" ids="system-message-1" level="3" line="11" source="test data" type="ERROR">
@@ -840,7 +839,7 @@
<title refid="toc-entry-1">
Section
<paragraph>
- Testing an
+ Testing an \n\
<reference name="indirect reference to the table of contents" refid="table-of-contents">
indirect reference to the table of contents
.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|