[IPython-dev] Highlight lines of code in code cells?
Matthias BUSSONNIER
bussonniermatthias at gmail.com
Mon Dec 2 12:01:02 EST 2013
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
More information about the IPython-dev
mailing list