Show More
@@ -12,7 +12,6 b' called nb_figure_NN.png.' | |||||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | from __future__ import print_function |
|
13 | from __future__ import print_function | |
14 |
|
14 | |||
15 |
|
||||
16 | # From IPython |
|
15 | # From IPython | |
17 | from IPython.external import argparse |
|
16 | from IPython.external import argparse | |
18 |
|
17 | |||
@@ -25,35 +24,40 b' from converters.latex import ConverterLaTeX' | |||||
25 | from converters.notebook import ConverterNotebook |
|
24 | from converters.notebook import ConverterNotebook | |
26 | from converters.python import ConverterPy |
|
25 | from converters.python import ConverterPy | |
27 |
|
26 | |||
28 | known_formats = "rst (default), html, blogger-html, latex, markdown, py" |
|
27 | ||
|
28 | # When adding a new format, make sure to add it to the `converters` | |||
|
29 | # dictionary below. This is used to create the list of known formats, | |||
|
30 | # which gets printed in case an unknown format is encounteres, as well | |||
|
31 | # as in the help | |||
|
32 | ||||
|
33 | converters = { | |||
|
34 | 'rst': ConverterRST, | |||
|
35 | 'markdown': ConverterMarkdown, | |||
|
36 | 'html': ConverterHTML, | |||
|
37 | 'blogger-html': ConverterBloggerHTML, | |||
|
38 | 'latex': ConverterLaTeX, | |||
|
39 | 'py': ConverterPy, | |||
|
40 | } | |||
|
41 | ||||
|
42 | default_format = 'rst' | |||
|
43 | ||||
|
44 | # Extract the list of known formats and mark the first format as the default. | |||
|
45 | known_formats = ', '.join([key + " (default)" if key == default_format else key | |||
|
46 | for key in converters]) | |||
|
47 | ||||
29 |
|
48 | |||
30 | def main(infile, format='rst'): |
|
49 | def main(infile, format='rst'): | |
31 | """Convert a notebook to html in one step""" |
|
50 | """Convert a notebook to html in one step""" | |
32 | # XXX: this is just quick and dirty for now. When adding a new format, |
|
51 | ||
33 | # make sure to add it to the `known_formats` string above, which gets |
|
52 | try: | |
34 | # printed in in the catch-all else, as well as in the help |
|
53 | ConverterClass = converters[format] | |
35 | if format == 'rst': |
|
54 | except KeyError: | |
36 | converter = ConverterRST(infile) |
|
|||
37 | converter.render() |
|
|||
38 | elif format == 'markdown': |
|
|||
39 | converter = ConverterMarkdown(infile) |
|
|||
40 | converter.render() |
|
|||
41 | elif format == 'html': |
|
|||
42 | converter = ConverterHTML(infile) |
|
|||
43 | converter.render() |
|
|||
44 | elif format == 'blogger-html': |
|
|||
45 | converter = ConverterBloggerHTML(infile) |
|
|||
46 | converter.render() |
|
|||
47 | elif format == 'latex': |
|
|||
48 | converter = ConverterLaTeX(infile) |
|
|||
49 | converter.render() |
|
|||
50 | elif format == 'py': |
|
|||
51 | converter = ConverterPy(infile) |
|
|||
52 | converter.render() |
|
|||
53 | else: |
|
|||
54 | raise SystemExit("Unknown format '%s', " % format + |
|
55 | raise SystemExit("Unknown format '%s', " % format + | |
55 | "known formats are: " + known_formats) |
|
56 | "known formats are: " + known_formats) | |
56 |
|
57 | |||
|
58 | converter = ConverterClass(infile) | |||
|
59 | converter.render() | |||
|
60 | ||||
57 | #----------------------------------------------------------------------------- |
|
61 | #----------------------------------------------------------------------------- | |
58 | # Script main |
|
62 | # Script main | |
59 | #----------------------------------------------------------------------------- |
|
63 | #----------------------------------------------------------------------------- |
@@ -21,7 +21,7 b' def clean_dir():' | |||||
21 | def test_simple(): |
|
21 | def test_simple(): | |
22 | c = ConverterRST(fname) |
|
22 | c = ConverterRST(fname) | |
23 | f = c.render() |
|
23 | f = c.render() | |
24 |
nt.assert_true('rst' |
|
24 | nt.assert_true(f.endswith('.rst'), 'changed file extension to rst') | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | @nt.with_setup(clean_dir, clean_dir) |
|
27 | @nt.with_setup(clean_dir, clean_dir) |
General Comments 0
You need to be logged in to leave comments.
Login now