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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9912
          http://sourceforge.net/p/docutils/code/9912
Author:   milde
Date:     2024-08-21 13:44:37 +0000 (Wed, 21 Aug 2024)
Log Message:
-----------
HTML writer: Fix part "html_head" if "output_encoding" setting is 'unicode'.

If the output encoding is not determined, part "head" does not contain
a "charset" `<meta>` element. So we must not drop the first element
from "head" when completing "html_head".

Fixup for [r9240].

Modified Paths:
--------------
    trunk/docutils/docutils/writers/_html_base.py
    trunk/docutils/test/test_writers/test_html5_polyglot_parts.py

Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py	2024-08-21 08:05:47 UTC (rev 9911)
+++ trunk/docutils/docutils/writers/_html_base.py	2024-08-21 13:44:37 UTC (rev 9912)
@@ -963,8 +963,12 @@
                 self.head.extend(self.math_header)
             else:
                 self.stylesheet.extend(self.math_header)
-        # skip content-type meta tag with interpolated charset value:
-        self.html_head.extend(self.head[1:])
+        if (self.settings.output_encoding  # may be None
+            and self.settings.output_encoding.lower() != 'unicode'):
+            # skip content-type meta tag with interpolated charset value:
+            self.html_head.extend(self.head[1:])
+        else:
+            self.html_head.extend(self.head)
         self.body_prefix.append(self.starttag(node, **self.documenttag_args))
         self.body_suffix.insert(0, f'</{self.documenttag_args["tagname"]}>\n')
         self.fragment.extend(self.body)  # self.fragment is the "naked" body

Modified: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-08-21 08:05:47 UTC (rev 9911)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-08-21 13:44:37 UTC (rev 9912)
@@ -84,7 +84,7 @@
                         settings_overrides={
                             '_disable_config': True,
                             'strict_visitor': True,
-                            'stylesheet': '',
+                            'stylesheet_path': '',
                             'section_self_link': True,
                             **settings_overrides,
                         }
@@ -143,8 +143,7 @@
 
 totest = {}
 
-totest['standard'] = ({'stylesheet_path': '',
-                       'embed_stylesheet': False}, [
+totest['standard'] = ({}, [
 ["""\
 Simple String
 """,
@@ -288,12 +287,22 @@
 }],
 ])
 
-totest['no_title_promotion'] = ({'doctitle_xform': False,
-                                 'stylesheet_path': '',
-                                 'embed_stylesheet': False}, [
+totest['standard'] = ({'output_encoding': 'unicode'}, [
 ["""\
 Simple String
 """,
+{'fragment': '<p>Simple String</p>\n',
+ 'meta': """\
+<meta name="generator" content="Docutils 0.22b.dev: https://docutils.sourceforge.io/" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+""",
+}],
+])
+
+totest['no_title_promotion'] = ({'doctitle_xform': False}, [
+["""\
+Simple String
+""",
 '<p>Simple String</p>\n',
 ],
 ["""\
@@ -574,8 +583,6 @@
 
 
 totest['lazy_loading'] = ({'image_loading': 'lazy',
-                           'stylesheet_path': '',
-                           'embed_stylesheet': False,
                            'report_level': 4}, [
 ["""\
 Lazy loading by default, overridden by :loading: option
@@ -606,9 +613,7 @@
 
 totest['root_prefix'] = ({'root_prefix': ROOT_PREFIX,
                           'image_loading': 'embed',
-                          'stylesheet_path': '',
                           'warning_stream': '',
-                          'embed_stylesheet': False
                           }, [
 ["""\
 .. image:: /data/blue%20square.png
@@ -630,9 +635,7 @@
 ])
 
 
-totest['no_backlinks'] = ({'footnote_backlinks': False,
-                           'stylesheet_path': '',
-                           'embed_stylesheet': False}, [
+totest['no_backlinks'] = ({'footnote_backlinks': False}, [
 
 ["""\
 Two footnotes [#f1]_ [#f2]_ and two citations [once]_ [twice]_.
@@ -673,7 +676,6 @@
 
 
 totest['syntax_highlight'] = ({'syntax_highlight': 'short',
-                               'stylesheet_path': '',
                                }, [
 ["""\
 .. code:: shell
@@ -701,9 +703,7 @@
 ])
 
 
-totest['system_messages'] = ({'stylesheet_path': '',
-                              'embed_stylesheet': False,
-                              'math_output': 'mathml',
+totest['system_messages'] = ({'math_output': 'mathml',
                               'warning_stream': '',
                               }, [
 ["""\
@@ -748,9 +748,7 @@
 """],
 ])
 
-totest['system_messages-PIL'] = ({'stylesheet_path': '',
-                                  'embed_stylesheet': False,
-                                  'math_output': 'mathml',
+totest['system_messages-PIL'] = ({'math_output': 'mathml',
                                   'warning_stream': '',
                                   }, [
 ["""\
@@ -816,9 +814,7 @@
 ],
 ])
 
-totest['no_system_messages'] = ({'stylesheet_path': '',
-                                 'embed_stylesheet': False,
-                                 'math_output': 'mathml',
+totest['no_system_messages'] = ({'math_output': 'mathml',
                                  'report_level': 4,
                                  'warning_stream': '',
                                  }, [

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.