SF.net SVN: docutils:[9866 ] trunk/docutils/docutils/w riters
milde--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9866
http://sourceforge.net/p/docutils/code/9866
Author: milde
Date: 2024-08-07 23:35:56 +0000 (Wed, 07 Aug 2024)
Log Message:
-----------
Use `unquote()` instead of `url2pathname()` to unquote image URIs.
Simplify the unquoting of the path segment of an image URI.
`url2pathname` also converts the path delimiters to the system default
and does some additional replacements under Windows which is not required
for the Docutils HTML or LaTeX writers.
Fixes [bugs: #493]
Modified Paths:
--------------
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/latex2e/__init__.py
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2024-08-07 23:35:42 UTC (rev 9865)
+++ trunk/docutils/docutils/writers/_html_base.py 2024-08-07 23:35:56 UTC (rev 9866)
@@ -626,7 +626,7 @@
uri_parts = urllib.parse.urlparse(uri)
if uri_parts.scheme not in ('', 'file'):
raise ValueError('Can only read local images.')
- imagepath = urllib.request.url2pathname(uri_parts.path)
+ imagepath = urllib.parse.unquote(uri_parts.path)
if imagepath.startswith('/'): # cf. config.html#root-prefix
root_prefix = Path(self.settings.root_prefix)
imagepath = (root_prefix/imagepath[1:]).as_posix()
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2024-08-07 23:35:42 UTC (rev 9865)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2024-08-07 23:35:56 UTC (rev 9866)
@@ -12,11 +12,11 @@
#
# convention deactivate code by two # i.e. ##.
-from pathlib import Path
import re
import string
-from urllib.request import url2pathname
+import urllib.parse
import warnings
+from pathlib import Path
from docutils import frontend, nodes, languages, writers, utils
from docutils.transforms import writer_aux
@@ -2400,8 +2400,8 @@
def visit_image(self, node) -> None:
self.requirements['graphicx'] = self.graphicx_package
attrs = node.attributes
- # Convert image URI to a local file path
- imagepath = url2pathname(attrs['uri']).replace('\\', '/')
+ # image URI may use %-encoding
+ imagepath = urllib.parse.unquote(attrs['uri'])
# alignment defaults:
if 'align' not in attrs:
# Set default align of image in a figure to 'center'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.