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

milde--- via Docutils-checkins <[email protected]> Tue, 13 May 2025 08:37:58 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10126
          http://sourceforge.net/p/docutils/code/10126
Author:   milde
Date:     2025-05-13 08:37:56 +0000 (Tue, 13 May 2025)
Log Message:
-----------
Fix problems with 3rd-party parsers.

Pass default settings to custom parser for included file.
When the "include" directive is used with a custom parser,
we must ensure the custom parser's default settings are present
in `document.settings`.

Fix error when determining the document metadata title from the
source path and the internal `source` attribute is ``None``.

Modified Paths:
--------------
    trunk/docutils/HISTORY.rst
    trunk/docutils/docutils/parsers/rst/directives/misc.py
    trunk/docutils/docutils/writers/_html_base.py

Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst	2025-05-06 17:40:56 UTC (rev 10125)
+++ trunk/docutils/HISTORY.rst	2025-05-13 08:37:56 UTC (rev 10126)
@@ -17,8 +17,16 @@
 Release 0.22rc2 (unpublished)
 =============================
 
-Nothing yet.
+* docutils/parsers/rst/directives/misc.py
 
+  - Pass default settings to custom parser for included file.
+
+* docutils/writers/_html_base.py
+
+  - Fix error when determining the document metadata title from the
+    source path and the internal `source` attribute is None.
+
+
 Release 0.22rc1 (2025-05-06)
 ============================
 

Modified: trunk/docutils/docutils/parsers/rst/directives/misc.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/misc.py	2025-05-06 17:40:56 UTC (rev 10125)
+++ trunk/docutils/docutils/parsers/rst/directives/misc.py	2025-05-13 08:37:56 UTC (rev 10126)
@@ -14,7 +14,7 @@
 from urllib.request import urlopen
 from urllib.error import URLError
 
-from docutils import io, nodes, statemachine, utils
+from docutils import frontend, io, nodes, statemachine, utils
 from docutils.parsers.rst import Directive, convert_directive_function
 from docutils.parsers.rst import directives, roles, states
 from docutils.parsers.rst.directives.body import CodeBlock, NumberLines
@@ -213,7 +213,11 @@
 
         Provisional.
         """
-        settings = self.settings.copy()
+        parser = self.options['parser']()
+        settings = frontend.get_default_settings(parser)
+        # update with current document settings
+        for k, v in self.settings.__dict__.items():
+            setattr(settings, k, v)
         settings._source = self.options['source']
         document = utils.new_document(settings._source, settings)
         document.include_log = self.state.document.include_log
@@ -220,7 +224,6 @@
         document.ids = self.state.document.ids
         document.nameids = self.state.document.nameids
         document.nametypes = self.state.document.nametypes
-        parser = self.options['parser']()
         parser.parse(text, document)
         self.state.document.parse_messages.extend(document.parse_messages)
         # clean up doctree and complete parsing

Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py	2025-05-06 17:40:56 UTC (rev 10125)
+++ trunk/docutils/docutils/writers/_html_base.py	2025-05-13 08:37:56 UTC (rev 10126)
@@ -937,7 +937,8 @@
         self.body.append('\n</pre>\n')
 
     def visit_document(self, node) -> None:
-        title = (node.get('title') or os.path.basename(node['source'])
+        title = (node.get('title')
+                 or os.path.basename(node.get('source') or '')
                  or 'untitled Docutils document')
         self.head.append(f'<title>{self.encode(title)}</title>\n')
 

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