##// END OF EJS Templates
more test fixed
more test fixed

File last commit:

r8620:66b7dfea
r8623:33ea591a
Show More
nbconvert.py
94 lines | 3.2 KiB | text/x-python | PythonLexer
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 #!/usr/bin/env python
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 """Convert IPython notebooks to other formats, such as ReST, and HTML.
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 Example:
MinRK
Add true HTML export...
r7914 ./nbconvert.py --format rst file.ipynb
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
MinRK
Add true HTML export...
r7914 Produces 'file.rst', along with auto-generated figure files
called nb_figure_NN.png.
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 """
Fernando Perez
Fix handling of local files with the /files/ pseudo-url.
r6677 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Fernando Perez
First working version of latex converter.
r6671 from __future__ import print_function
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
Fernando Perez
Fix handling of local files with the /files/ pseudo-url.
r6677 # Stdlib
Fernando Perez
Improve SVG support, other small fixes.
r6672 import codecs
MinRK
Add true HTML export...
r7914 import io
Fernando Perez
Fix handling of raw cells in all converters, add stderr to test nb
r6674 import logging
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 import os
Fernando Perez
First working version of latex converter.
r6671 import pprint
import re
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 import subprocess
import sys
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 import json
import copy
Paul Ivanov
make automatic __doc__ inheritance...
r8610 from types import FunctionType
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 from shutil import rmtree
Matthias BUSSONNIER
use markdown package instead instead of subprocess
r8163 from markdown import markdown
Fernando Perez
First working version of latex converter.
r6671
Fernando Perez
Fix handling of local files with the /files/ pseudo-url.
r6677 # From IPython
Paul Ivanov
use argparse from IPython
r6262 from IPython.external import argparse
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 from IPython.nbformat import current as nbformat
Paul Ivanov
remove unused import
r6257 from IPython.utils.text import indent
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 from IPython.nbformat.v3.nbjson import BytesEncoder
MinRK
Add true HTML export...
r7914 from IPython.utils import path, py3compat
# local
from lexers import IPythonLexer
Matthias BUSSONNIER
latex working
r8618 from converters.html import ConverterHTML
from converters.markdown import ConverterMarkdown
from converters.bloggerhtml import ConverterBloggerHTML
from converters.rst import ConverterRST
from converters.latex import ConverterLaTeX
Matthias BUSSONNIER
all seem to convert again
r8620 from converters.notebook import ConverterNotebook
from converters.python import ConverterPy
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366
Fernando Perez
Add blogger-html format option....
r8432 known_formats = "rst (default), html, blogger-html, latex, markdown, py"
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 def main(infile, format='rst'):
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 """Convert a notebook to html in one step"""
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 # XXX: this is just quick and dirty for now. When adding a new format,
# make sure to add it to the `known_formats` string above, which gets
# printed in in the catch-all else, as well as in the help
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 if format == 'rst':
converter = ConverterRST(infile)
converter.render()
Fernando Perez
Add first cut of markdown converter.x
r7812 elif format == 'markdown':
converter = ConverterMarkdown(infile)
converter.render()
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 elif format == 'html':
MinRK
Add true HTML export...
r7914 converter = ConverterHTML(infile)
htmlfname = converter.render()
Fernando Perez
Add blogger-html format option....
r8432 elif format == 'blogger-html':
converter = ConverterBloggerHTML(infile)
htmlfname = converter.render()
Fernando Perez
First working version of latex converter.
r6671 elif format == 'latex':
converter = ConverterLaTeX(infile)
latexfname = converter.render()
Paul Ivanov
added 'py' format, which is cleaner than PyWriter...
r8261 elif format == 'py':
converter = ConverterPy(infile)
converter.render()
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 else:
raise SystemExit("Unknown format '%s', " % format +
"known formats are: " + known_formats)
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
Fernando Perez
Fix handling of local files with the /files/ pseudo-url.
r6677 #-----------------------------------------------------------------------------
# Script main
#-----------------------------------------------------------------------------
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawTextHelpFormatter)
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 # TODO: consider passing file like object around, rather than filenames
# would allow us to process stdin, or even http streams
#parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
#Require a filename as a positional argument
parser.add_argument('infile', nargs=1)
Anton I. Sipos
Add help for format command line option.
r6265 parser.add_argument('-f', '--format', default='rst',
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 help='Output format. Supported formats: \n' +
known_formats)
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 args = parser.parse_args()
main(infile=args.infile[0], format=args.format)