Hey, thanks for the idea with the meta data! This could work well. I'll try 
soon.

On Tuesday, March 14, 2017 at 12:22:24 PM UTC+1, Kiko correoso garcia wrote:
>
> Sorry, a bug :-P, corrected version
>
> var cells = Jupyter.notebook.get_cells()
> for (var i=0;i<cells.length;i++){
>     if (cells[i].metadata['extract'] && cell*s[i]*.cell_type === "code"){
>         console.log(cells[i].get_text())        
>     }
> }
>
> 2017-03-14 12:20 GMT+01:00 Kiko <[email protected] <javascript:>>:
>
>>
>> 2017-03-14 11:20 GMT+01:00 Zelphir Kaltstahl <[email protected] 
>> <javascript:>>:
>>
>>> So as far as I know Jupyter Notebook uses the CodeMirror editor to 
>>> render code cells. In the CodeMirror documentation 
>>> <https://codemirror.net/doc/manual.html#api> I found the method 
>>> `doc.getValue` which is supposed to give the editor's content. According to 
>>> this 
>>> topic 
>>> <https://groups.google.com/forum/#%21searchin/jupyter/JS$20APi%7Csort:relevance/jupyter/1syLAOfC0jA/BgpRGN-FCgAJ>,
>>>  
>>> there is no documentation for the JS API of Jupyter Notebook.
>>>
>>> My question is: How do I get the (code) content of a/all code cell(s)? 
>>> Better even would be a way to get only the code cell's contents of code 
>>> cells, which are assigned a specific CSS class or other identifying feature.
>>>
>>
>> You could provide metadata to the cells you want to extract, e.g.:
>>
>> {
>>   "extract": true
>> }
>>
>> and then, from javascript, you could do:
>>
>> var cells = Jupyter.notebook.get_cells()
>> for (var i=0;i<cells.length;i++){
>>     if (cells[i].metadata['extract'] && cell.cell_type === "code"){
>>         console.log(cells[i].get_text())        
>>     }
>> }
>>  
>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Project Jupyter" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected] 
>>> <javascript:>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/jupyter/996ce1d8-607f-4fa0-b389-2fdf4f19c5bb%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/jupyter/996ce1d8-607f-4fa0-b389-2fdf4f19c5bb%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/710ad11d-2d51-4d95-b241-d07ff69d3030%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to