##// END OF EJS Templates
some improvement
some improvement

File last commit:

r9612:c336f65b
r9614:5acd1eec
Show More
runme.py
65 lines | 1.8 KiB | text/x-python | PythonLexer
Matthias BUSSONNIER
basic test for converter template
r9586 #!/usr/bin/env python
Matthias BUSSONNIER
rename runme2 to runme
r9612 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
fix utf8
r9589 from __future__ import print_function
Matthias BUSSONNIER
null template
r9580 import sys
Matthias BUSSONNIER
handle unicode output
r9581 import io
Matthias BUSSONNIER
rename runme2 to runme
r9612
Matthias BUSSONNIER
starting templates
r9578 from converters.template import *
Matthias BUSSONNIER
rename runme2 to runme
r9612 from converters.template import ConverterTemplate
from converters.html import ConverterHTML
# From IPython
# All the stuff needed for the configurable things
from IPython.config.application import Application
from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum
class NbconvertApp(Application):
def __init__(self, **kwargs):
super(NbconvertApp, self).__init__(**kwargs)
self.classes.insert(0,ConverterTemplate)
# ensure those are registerd
def initialize(self, argv=None):
self.parse_command_line(argv)
cl_config = self.config
self.update_config(cl_config)
def run(self):
"""Convert a notebook to html in one step"""
template_file = (self.extra_args or [None])[0]
ipynb_file = (self.extra_args or [None])[1]
template_file = sys.argv[1]
Matthias BUSSONNIER
multiple env
r9609
Matthias BUSSONNIER
rename runme2 to runme
r9612 if template_file.startswith('latex'):
tex_environement=True
else:
tex_environement=False
Matthias BUSSONNIER
lots of modification for latex
r9611
Matthias BUSSONNIER
rename runme2 to runme
r9612 C = ConverterTemplate(tplfile=sys.argv[1], tex_environement=tex_environement, config=self.config)
C.read(ipynb_file)
Matthias BUSSONNIER
multiple env
r9609
Matthias BUSSONNIER
rename runme2 to runme
r9612 output,rest = C.convert()
Matthias BUSSONNIER
multiple env
r9609
Matthias BUSSONNIER
rename runme2 to runme
r9612 print(output.encode('utf-8'))
Matthias BUSSONNIER
null template
r9580
Matthias BUSSONNIER
rename runme2 to runme
r9612 def main():
"""Convert a notebook to html in one step"""
app = NbconvertApp.instance()
app.initialize()
app.start()
app.run()
#-----------------------------------------------------------------------------
# Script main
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
Start to think on api...
r9601
Matthias BUSSONNIER
rename runme2 to runme
r9612 if __name__ == '__main__':
main()