[IPython-dev] Playing with cells in the notebook... and some problems.

Damián Avila damianavila at gmail.com
Thu Aug 8 02:01:29 EDT 2013


El 07/08/13 04:40, Matthias BUSSONNIER escribió:
> Le 7 août 2013 à 07:23, Damián Avila a écrit :
>
>> Ah... if I "wrapinner", the cell is executed without problems, but I
>> need to wrap outer, I mean add html elements enclosing the current cell...
> Cell object are attached to a DOM element, if yo wrap outer, you "change" this element
> so the binding do not exist anymore.
>
> it's  like this slight difference between (teleporting someone), and (cloning him and burn the original immediately)
> from an outsider perspective it's the same.
>
> You could probably re-attach cell.element to the wrapped tag, I think it is doable. But code mirror might also
> have some assumption on the DOM.
>
> I don't quite remember how are cell inserted and everything, but I would try when wrapping to do
> 	cell.to_json,
> 	create the sections
> 	create n <div>
> 	cell.from_json on each of theses div.
>

Hi Matthias, thank for you feedback...

I was experimenting in the notebook with no successful results.

Let me paste a little code to explain more deeply...

Essentially, I follow your guidelines... I select a cell marked as a 
fragment and pass it to JSON.
I created a new div prepended to the 'div#notebook-container'
Then I create a new code cell (I took the "kernel" status from the 
current cells, is there a better way to do it?) and pass back from JSON 
to this new "ccell".
Finally, I append the "ccell.element" to the new div...
In this way, I get the a copy of the cell but it is not executable...
If I do the same, but instead of appending the "ccell.element" to the 
new div, I append it to the 'div#notebook-container', the cell is 
executable again... so I think I am losing the DOM again...
(ah... in both cases I get the cell, but the input form is minimized and 
you have to click on it to expand it and write content... but this is 
not the main problem... just a detail for now...)

```
%%javascript
var cells = IPython.notebook.get_cells();
var jcell;
for(var i in cells){
   var cell = cells[i];
     if (cell.metadata.slideshow.slide_type == 'fragment') {
       jcell = cell.toJSON();
     }
}

$('div#notebook-container').prepend('<div id="slide"></div>');

var kernel = cells[0].kernel
var ccell = new IPython.CodeCell(kernel);
ccell.fromJSON(jcell);

$("div#slide").append(ccell.element);
```

Any insights?

Cheers.

Damián.



More information about the IPython-dev mailing list