SF.net SVN: docutils:[10263 ] trunk/docutils

milde--- via Docutils-checkins <[email protected]> Fri, 28 Nov 2025 13:51:32 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10263
          http://sourceforge.net/p/docutils/code/10263
Author:   milde
Date:     2025-11-28 13:51:32 +0000 (Fri, 28 Nov 2025)
Log Message:
-----------
Future-proof the test for valid parents of topics or sidebars.

Test a "whitelist" of categories before the "blacklist"
to allow auxiliary elements belonging to several categories
(e.g. `nodes.Root` and `nodes.BodyElements`) as parents
of topics or sidebars.
This still gives uncategorized nodes the "benefit of daubt"
but supports properly categorized nodes as well.

Modified Paths:
--------------
    trunk/docutils/HISTORY.rst
    trunk/docutils/docutils/parsers/rst/directives/body.py
    trunk/docutils/docutils/parsers/rst/directives/parts.py

Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst	2025-11-06 03:39:16 UTC (rev 10262)
+++ trunk/docutils/HISTORY.rst	2025-11-28 13:51:32 UTC (rev 10263)
@@ -17,9 +17,14 @@
 Release 0.22.4b1 (unpublished)
 ==============================
 
-.
+* docutils/parsers/rst/directives/body.py,
+  docutils/parsers/rst/directives/parts.py
 
+  - Test a "whitelist" of categories before the "blacklist" to allow
+    auxiliary elements belonging to several categories (e.g. `nodes.Root`
+    and `nodes.BodyElements`) as parents of topics or sidebars.
 
+
 Release 0.22.3 (2025-11-06)
 ===========================
 

Modified: trunk/docutils/docutils/parsers/rst/directives/body.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/body.py	2025-11-06 03:39:16 UTC (rev 10262)
+++ trunk/docutils/docutils/parsers/rst/directives/body.py	2025-11-28 13:51:32 UTC (rev 10263)
@@ -40,7 +40,9 @@
     """
 
     def run(self):
-        if isinstance(self.state_machine.node, self.invalid_parents):
+        if (not isinstance(self.state_machine.node,
+                           (nodes.Root, nodes.section, nodes.sidebar))
+            and isinstance(self.state_machine.node, self.invalid_parents)):
             raise self.error('The "%s" directive may not be used within '
                              'topics or body elements.' % self.name)
         self.assert_has_content()

Modified: trunk/docutils/docutils/parsers/rst/directives/parts.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/parts.py	2025-11-06 03:39:16 UTC (rev 10262)
+++ trunk/docutils/docutils/parsers/rst/directives/parts.py	2025-11-28 13:51:32 UTC (rev 10263)
@@ -44,8 +44,10 @@
                    'class': directives.class_option}
 
     def run(self):
-        if isinstance(self.state_machine.node,
-                      BasePseudoSection.invalid_parents):
+        if (not isinstance(self.state_machine.node,
+                           (nodes.Root, nodes.section, nodes.sidebar))
+            and isinstance(self.state_machine.node,
+                           BasePseudoSection.invalid_parents)):
             raise self.error('The "%s" directive may not be used within '
                              'topics or body elements.' % self.name)
         document = self.state_machine.document

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.