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: Failure in specifying user filter #3505

Closed
jakevdp opened this issue Jul 1, 2013 · 2 comments
Closed

nbconvert: Failure in specifying user filter #3505

jakevdp opened this issue Jul 1, 2013 · 2 comments
Milestone

Comments

@jakevdp
Copy link
Contributor

jakevdp commented Jul 1, 2013

I'm attempting to override the highlight filter for the notebook exporters. The following snippet leads to a failure:

from IPython.nbconvert.filters.highlight import _pygment_highlight
from pygments.formatters import HtmlFormatter
from IPython.nbformat import current as nbformat

from IPython.nbconvert.exporters import FullHtmlExporter


def my_highlight(source, language='ipython'):
    formatter = HtmlFormatter()
    return _pygment_highlight(source, formatter, language)

infile = 'test_notebook.ipynb'
outfile = 'test_notebook.html'

notebook = open(infile).read()
notebook_json = nbformat.reads_json(notebook)

exportHtml = FullHtmlExporter(filters={'highlight':my_highlight})
(body,resources) = exportHtml.from_notebook_node(notebook_json)

open(outfile, 'w').write(body)

This is the traceback:

Traceback (most recent call last):
  File "fail_case.py", line 19, in <module>
    exportHtml = FullHtmlExporter(filters={'highlight':my_highlight})
  File "/Users/jakevdp/Opensource/ipython/IPython/nbconvert/exporters/exporter.py", line 163, in __init__
    if issubclass(user_filter, MetaHasTraits):
TypeError: issubclass() arg 1 must be a class

Perhaps testing for isinstance(user_filter, type) would fix this -- though I'm not sure.

@jakevdp
Copy link
Contributor Author

jakevdp commented Jul 1, 2013

It looks like the offending line could be replaced with self.register_filter(key, user_filter). I tried this, and got a long and involved traceback. Note that the my_highlight function is identical to the highlight function that it is replacing: are user filters handled differently than default filters?

@Carreau
Copy link
Member

Carreau commented Jul 10, 2013

Fixed by #3512

@Carreau Carreau closed this as completed Jul 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants