SF.net SVN: docutils:[9724] trunk/docutils/docutils
milde--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9724
http://sourceforge.net/p/docutils/code/9724
Author: milde
Date: 2024-06-05 10:22:36 +0000 (Wed, 05 Jun 2024)
Log Message:
-----------
Doctree validation: validate also the element's descendants.
Recursive validation can be skipped setting the argument `recursive`
to False.
Modified Paths:
--------------
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/transforms/universal.py
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-06-05 10:22:23 UTC (rev 9723)
+++ trunk/docutils/docutils/nodes.py 2024-06-05 10:22:36 UTC (rev 9724)
@@ -1142,10 +1142,11 @@
+ '\n '.join(messages),
problematic_element=self)
- def validate(self):
+ def validate(self, recursive=True):
"""Validate Docutils Document Tree element ("doctree").
Raise ValidationError if there are violations.
+ If `recursive` is True, validate also the element's descendants.
See `The Docutils Document Tree`__ for details of the
Docutils Document Model.
@@ -1173,7 +1174,11 @@
raise ValueError(f'Element <{self.tagname}> invalid:\n '
+ '\n '.join(messages))
+ if recursive:
+ for child in self:
+ child.validate()
+
# ========
# Mixins
# ========
Modified: trunk/docutils/docutils/transforms/universal.py
===================================================================
--- trunk/docutils/docutils/transforms/universal.py 2024-06-05 10:22:23 UTC (rev 9723)
+++ trunk/docutils/docutils/transforms/universal.py 2024-06-05 10:22:36 UTC (rev 9724)
@@ -349,7 +349,7 @@
return
for node in self.document.findall():
try:
- node.validate()
+ node.validate(recursive=False)
except nodes.ValidationError as e:
self.document.reporter.warning(
str(e), base_node=e.problematic_element or node)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.