nbviewer icon indicating copy to clipboard operation
nbviewer copied to clipboard

line numbers on static html files?

Open ghost opened this issue 8 years ago • 4 comments

I find it useful to refer to particular segments of code within my Jupyter notebooks as blocks of code can easily stretch to more than 60 lines. Now, the following default option of adding line numbers is very useful.

However, what I would like is for the line numbers to be present in the static html files or PDF files(using pandoc). That way the line number feature is available for people who merely view static versions of my jupyter notebooks.

Is this feature available? If so, I'm not aware of it.

ghost avatar Feb 22 '17 14:02 ghost

It is not available on nbviewer, but it could be done in your own HTML exports with nbconvert by changing the pygments arguments used to handle code cells. You might have to resort to a custom template to change how pygments is called, if it's not exposed via configuration.

minrk avatar Feb 27 '17 12:02 minrk

Thanks, I'll try this. Shouldn't we also add this as a feature to Jupyter notebooks?

ghost avatar Feb 27 '17 12:02 ghost

Shouldn't we also add this as a feature to Jupyter notebooks?

I think the line numbering support in jupyter/notebook cells is a feature of the CodeMirror editor. On nbviewer, no such editor is present so line numbers would need to be added as part of the nbconvert process. Here's an idea from further back: https://github.com/ipython/ipython/issues/5847#issuecomment-57872057

I'd suggest opening an nbconvert ticket (or better: PR) if you'd like to see this possibly make its way to nbviewer, though we'd still have to figure out how to enable or disable it. Whether line numbers are enabled or not for a cell is not part of the ipynb schema at the moment.

parente avatar Jul 10 '18 03:07 parente

It is not available on nbviewer, but it could be done in your own HTML exports with nbconvert by changing the pygments arguments used to handle code cells. You might have to resort to a custom template to change how pygments is called, if it's not exposed via configuration.

I'm quite new to Jupyter and I was'nt able to write such a template. Would you have any example ?

pierrepageault avatar Jul 06 '19 12:07 pierrepageault