##// END OF EJS Templates
Moved add_prompts into correct location.
Jonathan Frederic -
Show More
@@ -182,33 +182,33 b' class Exporter(LoggingConfigurable):'
182 isclass = isinstance(preprocessor, type)
182 isclass = isinstance(preprocessor, type)
183 constructed = not isclass
183 constructed = not isclass
184
184
185 #Handle preprocessor's registration based on it's type
185 # Handle preprocessor's registration based on it's type
186 if constructed and isinstance(preprocessor, py3compat.string_types):
186 if constructed and isinstance(preprocessor, py3compat.string_types):
187 #preprocessor is a string, import the namespace and recursively call
187 # Preprocessor is a string, import the namespace and recursively call
188 #this register_preprocessor method
188 # this register_preprocessor method
189 preprocessor_cls = import_item(preprocessor)
189 preprocessor_cls = import_item(preprocessor)
190 return self.register_preprocessor(preprocessor_cls, enabled)
190 return self.register_preprocessor(preprocessor_cls, enabled)
191
191
192 if constructed and hasattr(preprocessor, '__call__'):
192 if constructed and hasattr(preprocessor, '__call__'):
193 #preprocessor is a function, no need to construct it.
193 # Preprocessor is a function, no need to construct it.
194 #Register and return the preprocessor.
194 # Register and return the preprocessor.
195 if enabled:
195 if enabled:
196 preprocessor.enabled = True
196 preprocessor.enabled = True
197 self._preprocessors.append(preprocessor)
197 self._preprocessors.append(preprocessor)
198 return preprocessor
198 return preprocessor
199
199
200 elif isclass and isinstance(preprocessor, MetaHasTraits):
200 elif isclass and isinstance(preprocessor, MetaHasTraits):
201 #preprocessor is configurable. Make sure to pass in new default for
201 # Preprocessor is configurable. Make sure to pass in new default for
202 #the enabled flag if one was specified.
202 # the enabled flag if one was specified.
203 self.register_preprocessor(preprocessor(parent=self), enabled)
203 self.register_preprocessor(preprocessor(parent=self), enabled)
204
204
205 elif isclass:
205 elif isclass:
206 #preprocessor is not configurable, construct it
206 # Preprocessor is not configurable, construct it
207 self.register_preprocessor(preprocessor(), enabled)
207 self.register_preprocessor(preprocessor(), enabled)
208
208
209 else:
209 else:
210 #preprocessor is an instance of something without a __call__
210 # Preprocessor is an instance of something without a __call__
211 #attribute.
211 # attribute.
212 raise TypeError('preprocessor')
212 raise TypeError('preprocessor')
213
213
214
214
@@ -40,6 +40,7 b' __all__ = ['
40 'ipython2python',
40 'ipython2python',
41 'posix_path',
41 'posix_path',
42 'path2url',
42 'path2url',
43 'add_prompts'
43 ]
44 ]
44
45
45
46
@@ -95,6 +96,16 b' def add_anchor(html):'
95 return py3compat.decode(ElementTree.tostring(h), 'utf-8')
96 return py3compat.decode(ElementTree.tostring(h), 'utf-8')
96
97
97
98
99 def add_prompts(code, first='>>> ', cont='... '):
100 """Add prompts to code snippets"""
101 new_code = []
102 code_list = code.split('\n')
103 new_code.append(first + code_list[0])
104 for line in code_list[1:]:
105 new_code.append(cont + line)
106 return '\n'.join(new_code)
107
108
98 def strip_dollars(text):
109 def strip_dollars(text):
99 """
110 """
100 Remove all dollar symbols from text
111 Remove all dollar symbols from text
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now