##// END OF EJS Templates
copy IPython application and loader
copy IPython application and loader

File last commit:

r8945:8a05044f
r8978:bd3dec14
Show More
nbconvert.py
87 lines | 3.3 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
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.python import ConverterPy
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366
Maximilian Albert
Much cleaner way of picking the right converter (inspired by a suggestion by Carreau).
r8728
# When adding a new format, make sure to add it to the `converters`
# dictionary below. This is used to create the list of known formats,
# which gets printed in case an unknown format is encounteres, as well
# as in the help
Maximilian Albert
Use a regular dictionary instead of OrderedDict.
r8731 converters = {
'rst': ConverterRST,
'markdown': ConverterMarkdown,
'html': ConverterHTML,
'blogger-html': ConverterBloggerHTML,
'latex': ConverterLaTeX,
'py': ConverterPy,
}
Maximilian Albert
Much cleaner way of picking the right converter (inspired by a suggestion by Carreau).
r8728
Maximilian Albert
Use a regular dictionary instead of OrderedDict.
r8731 default_format = 'rst'
Maximilian Albert
Better way of marking the default format (thanks to Carreau for the suggestion).
r8730
Maximilian Albert
Much cleaner way of picking the right converter (inspired by a suggestion by Carreau).
r8728 # Extract the list of known formats and mark the first format as the default.
Maximilian Albert
Better way of marking the default format (thanks to Carreau for the suggestion).
r8730 known_formats = ', '.join([key + " (default)" if key == default_format else key
Maximilian Albert
Drop .keys() since iteration over dictionaries automatically uses them.
r8733 for key in converters])
Maximilian Albert
Much cleaner way of picking the right converter (inspired by a suggestion by Carreau).
r8728
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
Bussonnier Matthias
fix text for exclude
r8945 def main(infile, format='rst', preamble=None, exclude=[],
David Warde-Farley
Match existing highlight_source convention....
r8778 highlight_source=True):
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220 """Convert a notebook to html in one step"""
Maximilian Albert
Much cleaner way of picking the right converter (inspired by a suggestion by Carreau).
r8728 try:
ConverterClass = converters[format]
except KeyError:
Paul Ivanov
list known formats in help & on unknown fmt error...
r6280 raise SystemExit("Unknown format '%s', " % format +
Rick Lupton
LaTeX converter: command line args for preamble filename and to exclude certain cell types
r8750 "known formats are: " + known_formats)
Fernando Perez
Initial checkin - note that in this state, it's producing an ipython...
r6220
Matthias BUSSONNIER
restore --exclude flag
r8912 converter = ConverterClass(infile, highlight_source=highlight_source, exclude=exclude)
Maximilian Albert
Much cleaner way of picking the right converter (inspired by a suggestion by Carreau).
r8728 converter.render()
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
David Warde-Farley
PEP8-ify rest of the repository.
r8749 #parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
# default=sys.stdin)
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261
#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)
Rick Lupton
LaTeX converter: command line args for preamble filename and to exclude certain cell types
r8750 parser.add_argument('-p', '--preamble',
help='Path to a user-specified preamble file')
Rick Lupton
Options to exclude certain sections (source code or cell output) from exported result
r8753 parser.add_argument('-e', '--exclude', default='',
help='Comma-separated list of cells to exclude')
Ivan Djokic
Changed name of argument command to remove highlighting; also added a fallback of True to the highlight argument in several places in case it's called without said argument.
r8773 parser.add_argument('-H', '--no-highlighting', action='store_false',
help='Disable syntax highlighting for code blocks.')
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 args = parser.parse_args()
Rick Lupton
Options to exclude certain sections (source code or cell output) from exported result
r8753 exclude_cells = [s.strip() for s in args.exclude.split(',')]
Ivan Djokic
Added an option to disable syntax highlighting in code blocks. Simply add the -p or --plain_output tag to the command. This is a fix for issue #21
r8772
Ivan Djokic
Rearranged order of arguments for functions dealing with highlight_code in order to preserve backwards compatability.
r8775 main(infile=args.infile[0], format=args.format, preamble=args.preamble,
Matthias BUSSONNIER
fix typo after #61 merge making ./nbconvert crash...
r8882 exclude=exclude_cells, highlight_source=args.no_highlighting)