[IPython-dev] Template cells

Brian Granger ellisonbg@gmail....
Sat Dec 15 14:13:48 CST 2012


On Sat, Dec 15, 2012 at 12:03 PM, Matthias BUSSONNIER
<bussonniermatthias@gmail.com> wrote:
>
> Le 15 déc. 2012 à 20:07, Thomas Kluyver a écrit :
>
>> Revisiting a discussion from a few days ago, to get more input.
>>
>> At one point, we were considering ways to interpolate variables from the Python namespace into Markdown cells, using custom syntax and transferring simple variables using the user_expressions field of execution messages.
>>
>> Prompted by another discussion, I felt that this approach was quite limiting, and a better approach would be to have a 'template cell', designed like this:
>>
> I like the idea of template, I'm still wondering if it is not going too far.

Hmm, there are somethings that i like about this for sure.  But I
worry that we are creating some nasty bastard child of Markdown +
LateX/MathJax + Templating that is going to haunt in in our later
years when we have to care for this beast.  This is a concern as other
people create frontends for the notebook - it will become difficult
the further we deviate away from plain Markdown

>> - To the user, it works like a Markdown cell; when they leave the cell, the editor is replaced by the rendered version of the contents.
>> - Since we now depend on Jinja2 for the notebook, we use the template syntax from that, rather than reinventing a restricted template syntax ourselves. This gives us things like loops in the templates.
>
> Jinja is python only, am I wrong ? And feel this would be a little too restrictive, moreover it will mix what the kernel does and what the server does.
> I'm not a big fan of having the server computing repr for the frontend... (even if we will have to go through this for multiuser)

In 10 years, the IPython Notebok will be largely language independent.
 Because of this, I don't think we want to pick a templating language
that is native to python.  It would need to be more general.

>> - To render the cell, it is sent to the kernel as an execution request.
> You stat to imply that the kernel does know it speaks to notebook...

I *really* want to avoid having to involve the server to render
Markdown cells.  Are there any nice JS templating engines?

>> - The rendering uses our display infrastructure, so e.g. the HTML representation of an object is preferred. But the template can override this to get the plain text repr.
>>
>> Open questions:
>> - Should the templates be in Markdown (for consistency with other rich-text cells), or in HTML (which is more common in templating)?
>> - If in Markdown, should they be an automatic feature of Markdown cells (i.e. the Javascript looks for template syntax, and decides to send it to the kernel)? Or is that too surprising?
>> - How can we ensure notebooks with template cells work with current versions of IPython, which don't know about them?
> This one is tough.
>
>> - Should there be any way to tell template cells to automatically re-render, e.g. on a timer, or after another cell is executed?
> It would lead to confusion unless the cell is explicitly and visually marked as being a live representation of the kernel.
>
> Why not a Jinja2 object in python that could return what you wish ?
>
> If you can show user_expression/variable in mdcell, you just have to reference this Jinja object... it has the same effect no ?
> And you could change the template engine if the kernel is not Python...

My gut feeling on this is that there are some nice ideas in this, but
that we need to sit on it for now and see how things develop with the
notebook and interactive widgets, which will provide an incredible
amount of flexibility in the notebook.  As a simpler target, I think
we should go back to Matthias's literate programming PR and think
carefully about the syntax of it.  I *love* the capability, but am
very hesitant to deviate from Markdown any further than we already
have.

Cheers,

Brian

> --
> Matthias
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev



--
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


More information about the IPython-dev mailing list