##// END OF EJS Templates
remove and clean code
Matthias BUSSONNIER -
Show More
@@ -18,17 +18,11 b' a conversion of IPython notebooks to some other format should inherit.'
18 18 from __future__ import print_function, absolute_import
19 19
20 20 # Stdlib imports
21 import jinja2
22 import codecs
23 21 import io
24 import logging
25 22 import os
26 23 from IPython.utils import path
27 import pprint
28 import re
29 from types import FunctionType
30 24
31 from jinja2 import Environment, PackageLoader, FileSystemLoader
25 from jinja2 import Environment, FileSystemLoader
32 26 env = Environment(
33 27 loader=FileSystemLoader('./templates/'),
34 28 extensions=['jinja2.ext.loopcontrols']
@@ -36,15 +30,14 b' env = Environment('
36 30
37 31 # IPython imports
38 32 from IPython.nbformat import current as nbformat
39 from IPython.config.configurable import Configurable, SingletonConfigurable
40 from IPython.utils.traitlets import (List, Unicode, Type, Bool, Dict, CaselessStrEnum,
41 Any)
33 from IPython.config.configurable import Configurable
34 from IPython.utils.traitlets import ( Unicode, Any)
42 35
43 36 # Our own imports
44 37 from IPython.utils.text import indent
45 38 from .utils import remove_ansi
46 39 from markdown import markdown
47 from .utils import highlight,ansi2html
40 from .utils import highlight, ansi2html
48 41 #-----------------------------------------------------------------------------
49 42 # Class declarations
50 43 #-----------------------------------------------------------------------------
@@ -61,43 +54,43 b' def python_comment(string):'
61 54
62 55
63 56 def header_body():
64 """Return the body of the header as a list of strings."""
65
66 from pygments.formatters import HtmlFormatter
67
68 header = []
69 static = os.path.join(path.get_ipython_package_dir(),
70 'frontend', 'html', 'notebook', 'static',
71 )
72 here = os.path.split(os.path.realpath(__file__))[0]
73 css = os.path.join(static, 'css')
74 for sheet in [
75 # do we need jquery and prettify?
76 # os.path.join(static, 'jquery', 'css', 'themes', 'base',
77 # 'jquery-ui.min.css'),
78 # os.path.join(static, 'prettify', 'prettify.css'),
79 os.path.join(css, 'boilerplate.css'),
80 os.path.join(css, 'fbm.css'),
81 os.path.join(css, 'notebook.css'),
82 os.path.join(css, 'renderedhtml.css'),
83 # our overrides:
84 os.path.join(here, '..', 'css', 'static_html.css'),
85 ]:
86
87 with io.open(sheet, encoding='utf-8') as f:
88 s = f.read()
89 header.append(s)
90
91 pygments_css = HtmlFormatter().get_style_defs('.highlight')
92 header.append(pygments_css)
93 return header
94
95 inlining= {}
57 """Return the body of the header as a list of strings."""
58
59 from pygments.formatters import HtmlFormatter
60
61 header = []
62 static = os.path.join(path.get_ipython_package_dir(),
63 'frontend', 'html', 'notebook', 'static',
64 )
65 here = os.path.split(os.path.realpath(__file__))[0]
66 css = os.path.join(static, 'css')
67 for sheet in [
68 # do we need jquery and prettify?
69 # os.path.join(static, 'jquery', 'css', 'themes', 'base',
70 # 'jquery-ui.min.css'),
71 # os.path.join(static, 'prettify', 'prettify.css'),
72 os.path.join(css, 'boilerplate.css'),
73 os.path.join(css, 'fbm.css'),
74 os.path.join(css, 'notebook.css'),
75 os.path.join(css, 'renderedhtml.css'),
76 # our overrides:
77 os.path.join(here, '..', 'css', 'static_html.css'),
78 ]:
79
80 with io.open(sheet, encoding='utf-8') as f:
81 s = f.read()
82 header.append(s)
83
84 pygments_css = HtmlFormatter().get_style_defs('.highlight')
85 header.append(pygments_css)
86 return header
87
88 inlining = {}
96 89 inlining['css'] = header_body()
97 90
98 91
99 92 def filter_data_type(output):
100 for fmt in ['html', 'pdf', 'svg', 'latex','png', 'jpg','jpeg' , 'text']:
93 for fmt in ['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text']:
101 94 if fmt in output:
102 95 return [fmt]
103 96
@@ -125,12 +118,8 b' class ConverterTemplate(Configurable):'
125 118
126 119 def __init__(self, tplfile='fullhtml', config=None, **kw):
127 120 self.template = env.get_template(tplfile+'.tpl')
128 super(ConverterTemplate,self).__init__(config=config)
129
130 def _get_prompt_number(self, cell):
131 return cell.prompt_number if hasattr(cell, 'prompt_number') \
132 else self.blank_symbol
133
121 self.nb = None
122 super(ConverterTemplate, self).__init__(config=config, **kw)
134 123
135 124 def process(self):
136 125 converted_cells = []
@@ -138,7 +127,7 b' class ConverterTemplate(Configurable):'
138 127 for cell in worksheet.cells:
139 128 cell.type = cell.cell_type
140 129 cell.haspyout = False
141 for out in cell.get('outputs',[]):
130 for out in cell.get('outputs', []):
142 131 if out.output_type == 'pyout':
143 132 cell.haspyout = True
144 133 break
@@ -146,13 +135,13 b' class ConverterTemplate(Configurable):'
146 135
147 136 return converted_cells
148 137
149 def convert(self, cell_separator='\n'):
138 def convert(self):
150 139 """ convert the ipynb file
151 140
152 141 return both the converted ipynb file and a dict containing potential
153 142 other resources
154 143 """
155 return self.template.render(worksheets=self.process(), inlining=inlining),{}
144 return self.template.render(worksheets=self.process(), inlining=inlining), {}
156 145
157 146
158 147 def read(self, filename):
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now