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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9690
          http://sourceforge.net/p/docutils/code/9690
Author:   milde
Date:     2024-05-06 12:41:07 +0000 (Mon, 06 May 2024)
Log Message:
-----------
Doctree validation: New configuration setting "validate".

New parser configuration setting "validate".

If True, the parser calls `document.validate()` in `finish_parse()`.

Useful for testing/debugging purposes and with the upcoming
"Docutils XML" parser.

Modified Paths:
--------------
    trunk/docutils/docs/user/config.txt
    trunk/docutils/docutils/parsers/__init__.py
    trunk/docutils/test/data/help/docutils.txt
    trunk/docutils/test/data/help/rst2html.txt
    trunk/docutils/test/data/help/rst2latex.txt

Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt	2024-05-06 08:32:22 UTC (rev 9689)
+++ trunk/docutils/docs/user/config.txt	2024-05-06 12:41:07 UTC (rev 9690)
@@ -635,7 +635,7 @@
 strict_visitor
 --------------
 
-When processing a document tree with the Visitor pattern, raise an
+When processing a `document tree`_ with the Visitor pattern, raise an
 error if a writer does not support a node type listed as optional.
 For transitional development use.
 
@@ -647,7 +647,7 @@
 -------------
 
 List of "classes" attribute values (comma-separated_) that will be
-removed from all elements in the document tree.
+removed from all elements in the `document tree`_.
 Values are appended. [#append-values]_
 
 Allows eliding class values that interfere with, e.g, CSS rules from 3rd
@@ -662,7 +662,7 @@
 strip_comments
 --------------
 
-Enable or disable the removal of comment elements from the document tree.
+Enable or disable the removal of comment elements from the `document tree`_.
 
 :Default: None (disabled).
 :Options: ``--strip-comments``, ``--leave-comments``.
@@ -673,7 +673,7 @@
 
 List of "classes" attribute values (comma-separated_).
 Values are appended. [#append-values]_
-Matching elements are removed from the document tree.
+Matching elements are removed from the `document tree`_.
 
 .. WARNING:: Potentially dangerous: may lead to an invalid document tree
    and subsequent writer errors.  Use with caution.
@@ -723,9 +723,7 @@
 .. [#] unless Docutils is run programmatically
        using the `Publisher Interface`_
 
-.. _Publisher Interface: ../api/publisher.html
 
-
 warning_stream
 --------------
 
@@ -776,6 +774,14 @@
 *Default*: True.  *Options*: ``--raw-enabled``, ``--no-raw``.
 
 
+validate
+--------
+
+Validate the parsing result.
+
+*Default*: False.  *Options*: ``--validate``, ``--no-validation``.
+
+
 [restructuredtext parser]
 -------------------------
 
@@ -2410,9 +2416,13 @@
 
 .. References
 
+.. _Document Tree: ../ref/doctree.html
+
 .. _Docutils Runtime Settings:
 .. _runtime settings: ../api/runtime-settings.html
 
+.. _Publisher Interface: ../api/publisher.html
+
 .. RestructuredText Directives
 .. _"class" directive: ../ref/rst/directives.html#class
 .. _"code": ../ref/rst/directives.html#code

Modified: trunk/docutils/docutils/parsers/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/__init__.py	2024-05-06 08:32:22 UTC (rev 9689)
+++ trunk/docutils/docutils/parsers/__init__.py	2024-05-06 12:41:07 UTC (rev 9690)
@@ -39,6 +39,13 @@
           ['--line-length-limit'],
           {'metavar': '<length>', 'type': 'int', 'default': 10000,
            'validator': frontend.validate_nonnegative_int}),
+         ('Validate the document tree after parsing.',
+          ['--validate'],
+          {'action': 'store_true',
+           'validator': frontend.validate_boolean}),
+         ('Do not validate the document tree. (default)',
+          ['--no-validation'],
+          {'action': 'store_false', 'dest': 'validate'}),
          )
         )
     component_type = 'parser'
@@ -62,6 +69,8 @@
         """Finalize parse details.  Call at end of `self.parse()`."""
         self.document.reporter.detach_observer(
             self.document.note_parse_message)
+        if self.document.settings.validate:
+            self.document.validate()
 
 
 _parser_aliases = {  # short names for known parsers

Modified: trunk/docutils/test/data/help/docutils.txt
===================================================================
--- trunk/docutils/test/data/help/docutils.txt	2024-05-06 08:32:22 UTC (rev 9689)
+++ trunk/docutils/test/data/help/docutils.txt	2024-05-06 12:41:07 UTC (rev 9690)
@@ -99,6 +99,8 @@
 --line-length-limit=<length>
                         Maximal number of characters in an input line. Default
                         10 000.
+--validate              Validate the document tree after parsing.
+--no-validation         Do not validate the document tree. (default)
 
 reStructuredText Parser Options
 -------------------------------

Modified: trunk/docutils/test/data/help/rst2html.txt
===================================================================
--- trunk/docutils/test/data/help/rst2html.txt	2024-05-06 08:32:22 UTC (rev 9689)
+++ trunk/docutils/test/data/help/rst2html.txt	2024-05-06 12:41:07 UTC (rev 9690)
@@ -100,6 +100,8 @@
 --line-length-limit=<length>
                         Maximal number of characters in an input line. Default
                         10 000.
+--validate              Validate the document tree after parsing.
+--no-validation         Do not validate the document tree. (default)
 
 reStructuredText Parser Options
 -------------------------------

Modified: trunk/docutils/test/data/help/rst2latex.txt
===================================================================
--- trunk/docutils/test/data/help/rst2latex.txt	2024-05-06 08:32:22 UTC (rev 9689)
+++ trunk/docutils/test/data/help/rst2latex.txt	2024-05-06 12:41:07 UTC (rev 9690)
@@ -100,6 +100,8 @@
 --line-length-limit=<length>
                         Maximal number of characters in an input line. Default
                         10 000.
+--validate              Validate the document tree after parsing.
+--no-validation         Do not validate the document tree. (default)
 
 reStructuredText Parser Options
 -------------------------------

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.