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

When README.txt does not finish with a new line: Thumbnail doesn't work; raw html is displayed #165

Closed
trbedwards opened this issue Nov 15, 2016 · 7 comments
Labels

Comments

@trbedwards
Copy link

trbedwards commented Nov 15, 2016

I'm having issues trying to get Sphinx gallery to render thumbnails correctly.

When I build the documentation and open the gallery index.html on my web browser, some of the thumbnails are non-clickable. For those thumbnails that are non-clickable, I get this raw html displayed: <div class=”sphx-glr-thumbcontainer” tooltip=”This script prints ‘hello world’ “>. The problem is shown in the attached screenshot.

sphinx_gallery_screenshot

To reproduce this problem I created a simple directory structure like so:

example_sphinx_project/
  doc/
  examples/
    README.txt
    hello_script.py
    goodbye_script.py
  pysrc/
    mypackage/
      __init__.py
      mod1.py
      mod2.py

I ran sphinx_quickstart in doc/, using all the default options. In index.rst I added Examples <auto_examples/index.rst> to the toctree. In conf.py I added the following

sphinx_gallery_conf = {
  'examples_dirs': '../examples',
  'gallery_dirs': 'auto_examples'
} 

Yet my thumbnails don't work properly.

I've had this problem occur with sphinx_gallery 1.5.0 using sphinx 1.4.8 on Windows and sphinx 1.4.6 on Linux.

Thanks

@lesteve
Copy link
Member

lesteve commented Nov 15, 2016

Thanks for the precise description! A good way to make it easier to reproduce would be to attach a zip of your example_sphinx_project to the issue.

@trbedwards
Copy link
Author

Ah sorry about that, for some reason I thought that .zip files weren't allowed on github! Here it is attached
example_sphinx_project.zip

@lesteve
Copy link
Member

lesteve commented Nov 15, 2016

Being able to include zip files is a reasonably recent feature (maybe a few months ago?)

@trbedwards
Copy link
Author

trbedwards commented Nov 15, 2016

I had a closer look at the html, and I noticed something off about the double quotation marks in the div class. They appear to be non-ascii. So I had a look at the html source. Here is the div for the non-working bit (hello_world.py):

<div>&lt;div class=&#8221;sphx-glr-thumbcontainer&#8221; tooltip=&#8221;This script prints &#8216;hello world&#8217; &#8220;&gt;</div></blockquote>
<div class="figure" id="id1">
<img alt="../_images/sphx_glr_hello_script_thumb.png" src="../_images/sphx_glr_hello_script_thumb.png" />
<p class="caption"><span class="caption-text"><a class="reference internal" href="hello_script.html#sphx-glr-auto-examples-hello-script-py"><span class="std std-ref">Hello Script</span></a></span></p>
</div>

Compare this to the thumbnail that does work (goodbye_script.py)

<div class="sphx-glr-thumbcontainer" tooltip="This script prints 'goodbye world' "><div class="figure" id="id2">
<img alt="../_images/sphx_glr_goodbye_script_thumb.png" src="../_images/sphx_glr_goodbye_script_thumb.png" />
<p class="caption"><span class="caption-text"><a class="reference internal" href="goodbye_script.html#sphx-glr-auto-examples-goodbye-script-py"><span class="std std-ref">Goodbye Script</span></a></span></p>
</div>

@lesteve
Copy link
Member

lesteve commented Nov 15, 2016

Yep I can reproduce. Adding a newline at the end of your examples/README.txt fixes it I think.

@lesteve
Copy link
Member

lesteve commented Nov 15, 2016

To be honest my editor adds new lines automatically if there is none and I am guessing other editors do that as well, so that's probably part of the reason why we never spotted this bug.

It's very likely not too hard to fix and it's just a new line to add in the right place in the generated rst. Do open a PR if you have time to investigate further. If not we'll try to fix this one shortly.

@lesteve lesteve added the bug label Nov 15, 2016
@trbedwards
Copy link
Author

Thanks, I fixed the issue on my end by adding a new line to the end of each README.txt.
Usually my IDE warns me when there isn't a new line at the end, except with .txt files!

@lesteve lesteve changed the title Thumbnail doesn't work; raw html is displayed When README.txt does not finish with a new line: Thumbnail doesn't work; raw html is displayed Nov 15, 2016
Titan-C added a commit to Titan-C/sphinx-gallery that referenced this issue Nov 27, 2016
Titan-C added a commit to Titan-C/sphinx-gallery that referenced this issue Nov 27, 2016
@Titan-C Titan-C closed this as completed in 8afe55a Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants