The ODT writer has two problems with the way it handles the URIs provided in image (and figure) directives. First, it does not unescape them before passing them to the local file system. Second, it dereferences relative to the current working directory, not relative to the directory reST file.
The first case causes problems with images whose file names contain characters that can't be used in URIs without escaping. I ran into it because my files have spaces in their names. In order to get the HTML writer to work, I had to refer to the files using "%20" in place of each space. Not ideal, but acceptable. However, the ODT writer takes the image node's uri member and passes it directly to os.path.exists (In writers/odt_odt/__init__.py in the function check_file_exists) as though it were a file system path rather than a URI. Of course, on the file system, the file name has spaces, not %20s, so it couldn't find it. This part of the problem could probably be solved by passing the uri through the standard urllib.url2pathname function before calling any file system functions.
The second problem showed up when I tried to perform the generation with a current directory other than the one containing the reST file. In general, relative URIs are resolved against the directory containing the referring document (I couldn't find anything in the reST documentation declaring an exception, so I expect the common behavior). But, again, because the ODT writer doesn't modify the URI at all before using it as a path, Python's file system functions assume it is relative to the working directory. The solution here is probably to prepend the path from the working directory to the reST file's directory.
These problems may be more general than what I've seen so far. The other writers may be affected. Also, the other directives cause external files to be read may have similar problems.
I'm using docutils 0.7 with Python 2.7 32-bit running on Windows 7 Professional 64-bit.
Log in to post a comment.