-
Notifications
You must be signed in to change notification settings - Fork 207
Rendering HTML in examples #199
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
Comments
I was wondering if it was possible to render directly some HTML produced by the example script.
I would rather be against getting this feature. We capture stdout and
save the plots, and would rather stay within those boundaries. The idea
is that you can run the scripts directly from a python interpreter and
not meet inconveniences.
For instance, in jupyter notebooks, one can render some HTML
Yes jupyter notebooks are amazing but that is a different ecosystem than
us. Starting to support Jupyter notebooks features would imply we put
their ecosystem in our dependencies, that is not going to happen.
If that not currently supported, what would be the advised approach to add this functionality (either through `display(HTML(...))` or some other mechanism)? Thank you.
I encourage you to get creative and hack into our code. My approach
would be to save a file on disk with your desired output and then use
the support we give to rst syntax in the code annotations to do a
`literalinclude` of that file and render it as html.
This of course will not work directly with our current code, because
code is executed where the source file is but the output rst file is
saved in your documentation folder where Sphinx can find it to parse it
into html. So you will need to work your way around to give the correct
relative paths for the include on the simple side, or implement a way to
transport desired output files into the sphinx documentation folder.
|
@Titan-C Thanks a lot for this exhaustive response and sorry for my very late reply.. Following your explanations, I managed to make it work. Assuming that,
in order to render HTML contained in the tmp_dir = os.path.join('..', 'doc', 'examples')
if os.path.exists(tmp_dir):
# building the docs with sphinx-gallery
with open(os.path.join(tmp_dir, 'out.html'), 'wt') as fh:
fh.write(html_data)
else:
# running from a terminal or jupyter
from IPython.display import display, HTML
display(HTML(html_data))
####################################
# .. raw:: html
# :file: out.html The path manipulations are not very clean and I'm not sure how to control the order in which HTML, figures, and stdout are rendered, but in any case this works for my use case . A more complete example can be found here. Closing this issue, thanks! |
Since sphinx-gallery displays the example output on a web page, I was wondering if it was possible to render directly some HTML produced by the example script.
For instance, in jupyter notebooks, one can render some HTML with,
so if the example
.py
script contained adisplay(HTML(...))
call, is it possible to just embed the corresponding HTML code into the example page? I could not find anything about this topic in the docs.If that not currently supported, what would be the advised approach to add this functionality (either through
display(HTML(...))
or some other mechanism)? Thank you.The text was updated successfully, but these errors were encountered: