SF.net SVN: docutils:[9789 ] trunk/docutils/docutils/w riters/_html_base.py

aa-turner--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9789
          http://sourceforge.net/p/docutils/code/9789
Author:   aa-turner
Date:     2024-07-31 03:41:21 +0000 (Wed, 31 Jul 2024)
Log Message:
-----------
Fix line endings for broken SVG files

Modified Paths:
--------------
    trunk/docutils/docutils/writers/_html_base.py

Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py	2024-07-31 03:15:18 UTC (rev 9788)
+++ trunk/docutils/docutils/writers/_html_base.py	2024-07-31 03:41:21 UTC (rev 9789)
@@ -476,7 +476,10 @@
             self.messages.append(self.document.reporter.error(
                 f'Cannot parse SVG image "{node["uri"]}":\n  {err}',
                 base_node=node))
-            return imagedata.decode('utf-8')
+            # We initially open the file in binary mode,
+            # meaning universal newlines are not applied.
+            # Manually convert here before decoding.
+            return imagedata.replace(b'\r\n', b'\n').decode('utf-8')
         # apply image node attributes:
         if size_declaration:  # append to style, replacing width & height
             declarations = [d.strip() for d in svg.get('style', '').split(';')]

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.