##// END OF EJS Templates
multiple env
Matthias BUSSONNIER -
Show More
@@ -0,0 +1,56 b''
1 ((*- extends 'null.tplx' -*))
2
3 ((* block in_prompt *))
4 # In[(((cell.prompt_number if cell.prompt_number else ' ')))]:
5 ((* endblock in_prompt *))
6
7 ((* block output_prompt *))
8 # Out[(((cell.prompt_number)))]:((* endblock output_prompt *))
9
10 ((* block input *))((( cell.input )))
11 ((* endblock input *))
12
13
14 ((= Those Two are for error displaying
15 even if the first one seem to do nothing,
16 it introduces a new line
17
18 =))
19 ((* block pyerr *))((( super() )))
20 ((* endblock pyerr *))
21
22 ((* block traceback_line *))
23 ((( line |indent| rm_ansi )))((* endblock traceback_line *))
24 ((= .... =))
25
26
27 ((* block pyout *))
28 ((( output.text| indent | pycomment)))
29 ((* endblock pyout *))
30
31 ((* block stream *))
32 ((( output.text| indent | pycomment)))
33 ((* endblock stream *))
34
35
36
37
38 ((* block display_data scoped *))
39 # image file:
40 ((* endblock display_data *))
41
42 ((* block markdowncell scoped *))
43 ((( cell.source | pycomment )))
44 ((* endblock markdowncell *))
45
46 ((* block headingcell scoped *))
47 ((( '#' * cell.level )))((( cell.source | pycomment)))
48 ((* endblock headingcell *))
49
50 ((* block rawcell scoped *))
51 ((( cell.source | pycomment )))
52 ((* endblock rawcell *))
53
54 ((* block unknowncell scoped *))
55 unknown type (((cell.type)))
56 ((* endblock unknowncell *))
@@ -20,6 +20,7 b' from __future__ import print_function, absolute_import'
20 20 # Stdlib imports
21 21 import io
22 22 import os
23 import re
23 24 from IPython.utils import path
24 25
25 26 from jinja2 import Environment, FileSystemLoader
@@ -28,6 +29,11 b' env = Environment('
28 29 extensions=['jinja2.ext.loopcontrols']
29 30 )
30 31
32 texenv = Environment(
33 loader=FileSystemLoader('./templates/tex/'),
34 extensions=['jinja2.ext.loopcontrols']
35 )
36
31 37 # IPython imports
32 38 from IPython.nbformat import current as nbformat
33 39 from IPython.config.configurable import Configurable
@@ -105,6 +111,40 b" env.filters['highlight'] = highlight"
105 111 env.filters['ansi2html'] = ansi2html
106 112
107 113
114
115 LATEX_SUBS = (
116 (re.compile(r'\\'), r'\\textbackslash'),
117 (re.compile(r'([{}_#%&$])'), r'\\\1'),
118 (re.compile(r'~'), r'\~{}'),
119 (re.compile(r'\^'), r'\^{}'),
120 (re.compile(r'"'), r"''"),
121 (re.compile(r'\.\.\.+'), r'\\ldots'),
122 )
123
124 def escape_tex(value):
125 newval = value
126 for pattern, replacement in LATEX_SUBS:
127 newval = pattern.sub(replacement, newval)
128 return newval
129
130 texenv.block_start_string = '((*'
131 texenv.block_end_string = '*))'
132 texenv.variable_start_string = '((('
133 texenv.variable_end_string = ')))'
134 texenv.comment_start_string = '((='
135 texenv.comment_end_string = '=))'
136 texenv.filters['escape_tex'] = escape_tex
137
138 texenv.filters['filter_data_type'] = filter_data_type
139 texenv.filters['pycomment'] = python_comment
140 texenv.filters['indent'] = indent
141 texenv.filters['rm_fake'] = rm_fake
142 texenv.filters['rm_ansi'] = remove_ansi
143 texenv.filters['markdown'] = markdown
144 texenv.filters['highlight'] = highlight
145 texenv.filters['ansi2html'] = ansi2html
146
147
108 148 def haspyout_transformer(nb,_):
109 149 print('calling...')
110 150 for worksheet in nb.worksheets:
@@ -131,7 +171,7 b' class ConverterTemplate(Configurable):'
131 171
132 172 infile_dir = Unicode()
133 173
134 def __init__(self, tplfile='fullhtml', preprocessors=[], config=None, **kw):
174 def __init__(self, tplfile='fullhtml', preprocessors=[], config=None,tex_environement=False, **kw):
135 175 """
136 176 tplfile : jinja template file to process.
137 177
@@ -141,7 +181,9 b' class ConverterTemplate(Configurable):'
141 181 to extract/inline file,
142 182
143 183 """
144 self.template = env.get_template(tplfile+'.tpl')
184 self.env = texenv if tex_environement else env
185 self.ext = '.tplx' if tex_environement else '.tpl'
186 self.template = self.env.get_template(tplfile+self.ext)
145 187 self.nb = None
146 188 self.preprocessors = preprocessors
147 189 self.preprocessors.append(haspyout_transformer)
@@ -5,7 +5,15 b' from __future__ import print_function'
5 5 import sys
6 6 import io
7 7 from converters.template import *
8 C = ConverterTemplate(tplfile=sys.argv[1])
8
9 template_file = sys.argv[1]
10
11 if template_file.startswith('latex'):
12 tex_environement=True
13 else:
14 tex_environement=False
15
16 C = ConverterTemplate(tplfile=sys.argv[1], tex_environement=tex_environement)
9 17 C.read(sys.argv[2])
10 18
11 19 output,rest = C.convert()
General Comments 0
You need to be logged in to leave comments. Login now