Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbconvert line numbers #5847

Closed
justmytwospence opened this issue May 14, 2014 · 2 comments
Closed

nbconvert line numbers #5847

justmytwospence opened this issue May 14, 2014 · 2 comments
Milestone

Comments

@justmytwospence
Copy link

As far as I can tell from scouring the documentation and man pages, it's not possible to have nbconvert create line numbers when converting to html. Is this a feature thats implementable? Is there a DIY alternative?

@minrk
Copy link
Member

minrk commented Oct 3, 2014

Not with a command-line arg, but a custom nbconvert template and filter could get you line numbers with pygments.

To get pygments HTML with line numbers, specify the linenos argument to the HTMLFormatter:

formatter = pygments.formatters.get_formatter_by_name('html', linenos='inline')

for example

@minrk minrk closed this as completed Oct 3, 2014
@minrk minrk added this to the no action milestone Oct 3, 2014
yuvipanda added a commit to yuvipanda/nbconvert that referenced this issue Dec 1, 2021
I primarily want to allow for the possibility of line numbers
in HTML output. Pygments supports this natively, but we don't
have a way to pass arguments through to pygments.

A traitlet is added to allow passing arbitrary extra args
to the Pygments formatter, for Html and LaTeX. Should allow for
line number control and much more :)

This has been something folks have asked for for a while.

Ref ipython/ipython#5847
Ref jupyter#427
Ref yuvipanda/notebooksharing.space#34
SylvainCorlay pushed a commit to jupyter/nbconvert that referenced this issue Dec 2, 2021
I primarily want to allow for the possibility of line numbers
in HTML output. Pygments supports this natively, but we don't
have a way to pass arguments through to pygments.

A traitlet is added to allow passing arbitrary extra args
to the Pygments formatter, for Html and LaTeX. Should allow for
line number control and much more :)

This has been something folks have asked for for a while.

Ref ipython/ipython#5847
Ref #427
Ref yuvipanda/notebooksharing.space#34
@yuvipanda
Copy link

Thanks to jupyter/nbconvert#1683, you can now do this with:

jupyter nbconvert a.ipynb --to html --Highlight2HTML.extra_formatter_options linenos=table

Might need to wait for a release of nbconvert though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants