##// END OF EJS Templates
Merge pull request #49 from dwf/test_cleanup...
Merge pull request #49 from dwf/test_cleanup Test cleanup

File last commit:

r8625:b33307cc
r8737:8204f1ce merge
Show More
nbconvert.py
74 lines | 2.7 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
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
MinRK
Add true HTML export...
r7914
# local
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)
Matthias BUSSONNIER
pylinting 1
r8625 converter.render()
Fernando Perez
Add blogger-html format option....
r8432 elif format == 'blogger-html':
converter = ConverterBloggerHTML(infile)
Matthias BUSSONNIER
pylinting 1
r8625 converter.render()
Fernando Perez
First working version of latex converter.
r6671 elif format == 'latex':
converter = ConverterLaTeX(infile)
Matthias BUSSONNIER
pylinting 1
r8625 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)