Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative path to image does not render in restview #50

Open
alliefitter opened this issue Jan 20, 2018 · 3 comments
Open

Relative path to image does not render in restview #50

alliefitter opened this issue Jan 20, 2018 · 3 comments

Comments

@alliefitter
Copy link

Given a project with the structure:

foo/
  README.rst
img/
  bar.png

README.rst

.. image:: ../img/b.png

When README.rst is rendered in the browser, the image does not appear. Below are the logs:

127.0.0.1 - - [19/Jan/2018 19:23:24] code 404, message File not found: /img/bar.png
127.0.0.1 - - [19/Jan/2018 19:23:24] "GET /img/bar.png HTTP/1.1" 404 -

It looks like it's striping the ... When uploaded to GutHub, the images are rendered correctly.
restview version: 2.8.0
python version: 3.6

@mgedmin
Copy link
Owner

mgedmin commented Jan 20, 2018

If you have a project structured like this, and you run restview . at the top, you'll get a list of all .rst (and .txt) files. If you then click on foo/README.rst, the image will be visible.

If, on the other hand, you run restview README.rst inside the foo/ subdirectory, or restview foo/README.rst at the project root, the image will not be available. This is because the URL structure doesn't work. When README.rst is exposed at /, and you have a relative link starting with .., it has no upper level to climb to. As you can see in your pasted access log, the browser requests /img/bar.png and not /../img/bar.png, so restview is trying to find a img/bar.png in the directory that contains the README.rst. In fact if you create a symlink ln -s ../img bar/img, the images will start working.

Perhaps it would be nice if you could tell restview to serve everything under ., but ask it to open foo/README.rst instead of the list of files. Something like restview . --open foo/README.rst or restview foo/README.rst --root . maybe? I'm willing to accept such a pull request, but I don't know if I will find the time to work on it myself.

@alliefitter
Copy link
Author

Thanks for the response. That makes sense. My issue was not thinking of restview as a web server.

@mgedmin
Copy link
Owner

mgedmin commented Jan 22, 2018

Actually, perhaps I should stop thinking of restview as a web server and start thinking about it as a program that displays ReStructuredText documents. There's nothing preventing me from discovering all the image directives in the document, making a list of images, and rewriting them into URLs that work (plus making sure to expose them via HTTP).

Well, nothing except for lack of time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants