jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.72k stars 564 forks source link

Error while exporting notebook with links #480

Closed pprzetacznik closed 7 years ago

pprzetacznik commented 7 years ago

Hi,

while using version 4.2 I've noticed such problem. I've got (abcd)[http://link.to.some.page.com] markdown which causes such error after using nbconvert to convert my notebook to pdf:

(jupyter)[pankracy@piotrek-fedora rbm]$ jupyter nbconvert --to latex Untitled1.ipynb 
[NbConvertApp] Converting notebook Untitled1.ipynb to latex
Traceback (most recent call last):
  File "/home/Pankracy/Envs/jupyter/bin/jupyter-nbconvert", line 11, in <module>
    load_entry_point('nbconvert', 'console_scripts', 'jupyter-nbconvert')()
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/nbconvertapp.py", line 305, in start
    self.convert_notebooks()
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/nbconvertapp.py", line 473, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/nbconvertapp.py", line 444, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/nbconvertapp.py", line 373, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/exporter.py", line 166, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/exporter.py", line 184, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/latex.py", line 82, in from_notebook_node
    return super(LatexExporter, self).from_notebook_node(nb, resources, **kw)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/templateexporter.py", line 220, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/article.tplx", line 8, in top-level template code
    ((* extends cell_style *))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/style_ipython.tplx", line 56, in top-level template code
    ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/base.tplx", line 6, in top-level template code
    ((*- extends 'document_contents.tplx' -*))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/document_contents.tplx", line 50, in top-level template code
    ((*- block figure scoped -*))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/skeleton/display_priority.tplx", line 5, in top-level template code
    ((*- extends 'null.tplx' -*))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/skeleton/null.tplx", line 30, in top-level template code
    ((*- block body -*))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/base.tplx", line 173, in block "body"
    ((( super() )))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/skeleton/null.tplx", line 32, in block "body"
    ((*- block any_cell scoped -*))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/skeleton/null.tplx", line 76, in block "any_cell"
    ((*- block markdowncell scoped-*))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/exporters/../templates/latex/document_contents.tplx", line 67, in block "markdowncell"
    ((( cell.source | citation2latex | strip_files_prefix | convert_pandoc('markdown', 'json',extra_args=[]) | resolve_references | convert_pandoc('json','latex'))))
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/filters/filter_links.py", line 16, in resolve_references
    return applyJSONFilters([resolve_one_reference], source)
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/pandocfilters.py", line 197, in applyJSONFilters
    altered = walk(altered, action, format, meta)
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/pandocfilters.py", line 120, in walk
    array.append(walk(item, action, format, meta))
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/pandocfilters.py", line 113, in walk
    array.append(walk(item, action, format, meta))
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/pandocfilters.py", line 124, in walk
    x[k] = walk(x[k], action, format, meta)
  File "/home/Pankracy/Envs/jupyter/lib/python2.7/site-packages/pandocfilters.py", line 111, in walk
    item['c'] if 'c' in item else None, format, meta)
  File "/home/Pankracy/Envs/jupyter/src/nbconvert/nbconvert/filters/filter_links.py", line 29, in resolve_one_reference
    target = val[2][0]
IndexError: list index out of range

I would be grateful for any help.

Cheers, PIotrek

takluyver commented 7 years ago

What version of pandoc do you have? Run pandoc --version at a command line to find out.

@michaelpacer I remember running into this with bookbook, but I'd forgotten about it when we put it into nbconvert. We probably need to make the code robust to older versions of pandoc.

pprzetacznik commented 7 years ago

@takluyver

(jupyter)[pankracy@piotrek-fedora rbm]$ pandoc --version
pandoc 1.13.2
Compiled with texmath 0.8.0.1, highlighting-kate 0.5.11.1.
Syntax highlighting is supported for the following languages:
    abc, actionscript, ada, agda, apache, asn1, asp, awk, bash, bibtex, boo, c,
    changelog, clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css,
    curry, d, diff, djangotemplate, dockerfile, dot, doxygen, doxygenlua, dtd,
    eiffel, email, erlang, fasm, fortran, fsharp, gcc, glsl, gnuassembler, go,
    haskell, haxe, html, ini, isocpp, java, javadoc, javascript, json, jsp,
    julia, latex, lex, lilypond, literatecurry, literatehaskell, lua, m4,
    makefile, mandoc, markdown, mathematica, matlab, maxima, mediawiki,
    metafont, mips, modelines, modula2, modula3, monobasic, nasm, noweb,
    objectivec, objectivecpp, ocaml, octave, opencl, pascal, perl, php, pike,
    postscript, prolog, pure, python, r, relaxng, relaxngcompact, rest, rhtml,
    roff, ruby, rust, scala, scheme, sci, sed, sgml, sql, sqlmysql,
    sqlpostgresql, tcl, tcsh, texinfo, verilog, vhdl, xml, xorg, xslt, xul,
    yacc, yaml, zsh
Default user data directory: /home/Pankracy/.pandoc
Copyright (C) 2006-2014 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
mpacer commented 7 years ago

Could you try updating to a newer version of pandoc, I believe the most recent release (at the time of this writing) is in the 1.18 1.19 line?

takluyver commented 7 years ago

Yeah, I think the structure of pandoc's ast changed somewhere around 1.16 or 1.17, so your version will have the older structure.

pprzetacznik commented 7 years ago

Thanks, pandoc's upgrade also required upgrade of system but it's eventually working right now.