Repository: nilearn/nilearn

Issue:
Change iframe call for rendering in Jupyter Book
<!--
Hi! 
If you have: 
 -1 Questions about how to use Nilearn or 
 -2 Need analysis suggestions & recommendations?

A bunch of fMRI researchers hang out at Neurostars (http://neurostars.org/). 
Post those questions there. 
Add the tag `nilearn` (we get an email from Neurostars if you do).

Posting them here makes life more complicated for the Nilearn developers.  
-->

<!-- 
For the Feature Request,
Include the following:
------------------------
What would you like changed/added and why?
What would be the benefit? Does the change make something easier to use?
Clarifies something?
If it is a new feature, what is the benefit? 
-->

I would like to render interactive brainsprites generated from `view_img` in [Jupyter Book](https://github.com/jupyter/jupyter-book). Jupyter Book is built using Jekyll, and converts executed notebooks to markdown using nbconvert. The nbconvert is then converted to stylized HTML using kramdown.

My difficulty comes that kramdown [cannot currently handle unquoted attributes](https://github.com/jupyter/jupyter-book/issues/72) (even though these are valid HTML!). When we generate the iframe in which the brainsprite viewer is embedded here in nilearn, [we don't quote the `width` and `height` attributes](https://github.com/nilearn/nilearn/blob/ed86f29305a264693156826f0e429b2d6281eeaf/nilearn/plotting/js_plotting_utils.py#L126).

I'd like to open a simple fix to quote these two attributes, and smooth nilearn use with Jupyter Book. Would that be alright?



Discussion:
> I'd like to open a simple fix to quote these two attributes, and smooth nilearn
> use with Jupyter Book. Would that be alright?

That sounds no problem to me, though maybe I didn't understand the
proposed change.

I suggest that you open the PR and we look at it.

Cheers!


Resolving patch:
diff --git a/nilearn/plotting/js_plotting_utils.py b/nilearn/plotting/js_plotting_utils.py
--- a/nilearn/plotting/js_plotting_utils.py
+++ b/nilearn/plotting/js_plotting_utils.py
@@ -123,7 +123,7 @@ def get_iframe(self, width=None, height=None):
         if height is None:
             height = self.height
         escaped = escape(self.html, quote=True)
-        wrapped = ('<iframe srcdoc="{}" width={} height={} '
+        wrapped = ('<iframe srcdoc="{}" width="{}" height="{}" '
                    'frameBorder="0"></iframe>').format(escaped, width, height)
         return wrapped
 


Test patch:
diff --git a/nilearn/plotting/tests/test_js_plotting_utils.py b/nilearn/plotting/tests/test_js_plotting_utils.py
--- a/nilearn/plotting/tests/test_js_plotting_utils.py
+++ b/nilearn/plotting/tests/test_js_plotting_utils.py
@@ -239,8 +239,8 @@ def check_html(html, check_selects=True, plot_div_id='surface-plot'):
     resized = html.resize(3, 17)
     assert resized is html
     assert (html.width, html.height) == (3, 17)
-    assert "width=3 height=17" in html.get_iframe()
-    assert "width=33 height=37" in html.get_iframe(33, 37)
+    assert 'width="3" height="17"' in html.get_iframe()
+    assert 'width="33" height="37"' in html.get_iframe(33, 37)
     if not LXML_INSTALLED:
         return
     root = etree.HTML(html.html.encode('utf-8'),