##// END OF EJS Templates
pylinting 1
Matthias BUSSONNIER -
Show More
@@ -1,94 +1,74 b''
1 1 #!/usr/bin/env python
2 2 """Convert IPython notebooks to other formats, such as ReST, and HTML.
3 3
4 4 Example:
5 5 ./nbconvert.py --format rst file.ipynb
6 6
7 7 Produces 'file.rst', along with auto-generated figure files
8 8 called nb_figure_NN.png.
9 9 """
10 10 #-----------------------------------------------------------------------------
11 11 # Imports
12 12 #-----------------------------------------------------------------------------
13 13 from __future__ import print_function
14 14
15 # Stdlib
16 import codecs
17 import io
18 import logging
19 import os
20 import pprint
21 import re
22 import subprocess
23 import sys
24 import json
25 import copy
26 from types import FunctionType
27 from shutil import rmtree
28 from markdown import markdown
29 15
30 16 # From IPython
31 17 from IPython.external import argparse
32 from IPython.nbformat import current as nbformat
33 from IPython.utils.text import indent
34 from IPython.nbformat.v3.nbjson import BytesEncoder
35 from IPython.utils import path, py3compat
36 18
37 19 # local
38 from lexers import IPythonLexer
39
40 20 from converters.html import ConverterHTML
41 21 from converters.markdown import ConverterMarkdown
42 22 from converters.bloggerhtml import ConverterBloggerHTML
43 23 from converters.rst import ConverterRST
44 24 from converters.latex import ConverterLaTeX
45 25 from converters.notebook import ConverterNotebook
46 26 from converters.python import ConverterPy
47 27
48 28 known_formats = "rst (default), html, blogger-html, latex, markdown, py"
49 29
50 30 def main(infile, format='rst'):
51 31 """Convert a notebook to html in one step"""
52 32 # XXX: this is just quick and dirty for now. When adding a new format,
53 33 # make sure to add it to the `known_formats` string above, which gets
54 34 # printed in in the catch-all else, as well as in the help
55 35 if format == 'rst':
56 36 converter = ConverterRST(infile)
57 37 converter.render()
58 38 elif format == 'markdown':
59 39 converter = ConverterMarkdown(infile)
60 40 converter.render()
61 41 elif format == 'html':
62 42 converter = ConverterHTML(infile)
63 htmlfname = converter.render()
43 converter.render()
64 44 elif format == 'blogger-html':
65 45 converter = ConverterBloggerHTML(infile)
66 htmlfname = converter.render()
46 converter.render()
67 47 elif format == 'latex':
68 48 converter = ConverterLaTeX(infile)
69 latexfname = converter.render()
49 converter.render()
70 50 elif format == 'py':
71 51 converter = ConverterPy(infile)
72 52 converter.render()
73 53 else:
74 54 raise SystemExit("Unknown format '%s', " % format +
75 55 "known formats are: " + known_formats)
76 56
77 57 #-----------------------------------------------------------------------------
78 58 # Script main
79 59 #-----------------------------------------------------------------------------
80 60
81 61 if __name__ == '__main__':
82 62 parser = argparse.ArgumentParser(description=__doc__,
83 63 formatter_class=argparse.RawTextHelpFormatter)
84 64 # TODO: consider passing file like object around, rather than filenames
85 65 # would allow us to process stdin, or even http streams
86 66 #parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
87 67
88 68 #Require a filename as a positional argument
89 69 parser.add_argument('infile', nargs=1)
90 70 parser.add_argument('-f', '--format', default='rst',
91 71 help='Output format. Supported formats: \n' +
92 72 known_formats)
93 73 args = parser.parse_args()
94 74 main(infile=args.infile[0], format=args.format)
General Comments 0
You need to be logged in to leave comments. Login now