[IPython-dev] Highlight lines of code in code cells?

Eric Matthes ehmatthes at gmail.com
Mon Dec 2 18:57:32 EST 2013


Are you thinking of one name for a series of cells, or an individual name
for each cell?

It would be nice to give a series of cells the same name (or the same tag),
and then the notebook looks through the series of cells that have the same
name. Each successive cell with the same name gets diff'ed against the
previous cell of the same name/ tag, and the diff's get highlighted.

Eric


On Mon, Dec 2, 2013 at 2:19 PM, Greg Wilson <gvwilson at third-bit.com> wrote:

> On 2013-12-02 5:03 PM, Mark Voorhies wrote:
> > On 12/02/2013 09:26 AM, Eric Matthes wrote:
> >> I am not very familiar with the codebase yet, and I have few "good long
> >> afternoons" at this time of the year. I don't want to clutter my
> notebooks
> >> in a way that will be laborious to clean, so I think will use the
> >> commenting approach I described above, but also write a quick script
> that
> >> strips the notebooks of these formatting comments. This way anyone who
> is
> >> using the raw notebooks for their own purposes can choose to use my
> hack,
> >> or have a set of clean, unhighlighted notebooks to work with.
> >>
> >> I like the efficiency of your approach, though, so when I do get a nice
> >> afternoon to hack I will play with that approach. If anyone else has a
> good
> >> suggestion, I'd love to hear it as well.
> >>
> >> Thanks.
> >>
> >> Eric
> >>
> >>
> >> On Mon, Dec 2, 2013 at 8:01 AM, Matthias BUSSONNIER <
> >> bussonniermatthias at gmail.com> wrote:
> >>
> >>> Le 2 déc. 2013 à 17:37, Eric Matthes a écrit :
> >>>
> >>>> Hello,
> >>>>
> >>>> I often use IPython Notebook to write tutorials. In tutorials, I find
> it
> >>> helpful to highlight the lines of code that are being changed in each
> >>> iteration of a project. Is there a straightforward way to highlight
> >>> individual lines of code within a code cell?
> >>>> I came up with one approach, but it feels like an ugly hack. I write a
> >>> comment before the line[s] I want to highlight, and a comment after.
> Then
> >>> when converting to html I convert these comment lines to <b> and </b>.
> This
> >>> works, but it clutters the raw notebook file with formatting comments.
> >>>> ##bold
> >>>> print("I'd like to highlight this line.")
> >>>> ##/bold
> >>>>
> >>>> becomes:
> >>>>
> >>>> <b>print("I'd like to highlight this line.")</b>
> >>>>
> >>>> Is there a better way?
> >>> One could bind code mirror gutter event (click on line number) to store
> >>> metadata into the cells,
> >>> and write a custom highlighter for the templates in nbconvert.
> >>> This is more or less the only thing I  see. I would say that it's a
> good
> >>> long afternoon hack if you
> >>> are familiar with the codebase/codemirror and Pygment.
> >>>
> >>> It would have the advantage that you can easily toggle this highlight
> on
> >>> and of with a flag.
> >>>
> >>> --
> >>> Matthias
> > It would be very nice to have this as a cell magic that would highlight
> lines not in a reference
> > cell (or render as a diff relative to the reference cell).
> >
> > E.g.,
> >
> > [23] def Hello():
> >          print "Hello, World"
> >
> > [24] %%diff 23
> >        def Hello(s)
> >          print "Hello, %s" % s
> >
> > No idea how to do this, though =)
> >
> > --Mark
> >
> Software Carpentry would really like this feature as well, but I'd
> prefer not to tie it to cell numbers, since they change as the notebook
> is re-executed.  Instead, could we use cell tagging to give cells names,
> then display the diff against a named cell?
> Thanks,
> Greg
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20131202/33b758ce/attachment.html>


More information about the IPython-dev mailing list