##// END OF EJS Templates
Moved wrap code into Strings utility file.
Jonathan Frederic -
Show More
@@ -0,0 +1,29 b''
1 """String utilities.
2
3 Contains a collection of usefull string manipulations functions.
4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17 # Our own imports
18 import textwrap #TODO
19
20 #-----------------------------------------------------------------------------
21 # Functions
22 #-----------------------------------------------------------------------------
23 def wrap(text, width=100):
24 """ Try to detect and wrap paragraph"""
25
26 splitt = text.split('\n')
27 wrp = map(lambda x:textwrap.wrap(x,width),splitt)
28 wrpd = map('\n'.join, wrp)
29 return '\n'.join(wrpd) No newline at end of file
@@ -46,8 +46,7 b' from .utils import get_lines #TODO'
46 46 from .utils import remove_ansi #TODO
47 47 from .utils import highlight, ansi2html #TODO
48 48 from .latex_transformer import rm_math_space #TODO
49
50 import textwrap #TODO
49 from .utils.strings import wrap as _wrap
51 50
52 51 #Jinja2 filters
53 52 from .jinja_filters import (python_comment,
@@ -96,17 +95,6 b' LATEX_SUBS = ('
96 95 )
97 96
98 97 #-----------------------------------------------------------------------------
99 # Local utilities
100 #-----------------------------------------------------------------------------
101 #TODO: Move to utils.strings
102 def wrap(text, width=100):
103 """ Try to detect and wrap paragraph"""
104 splitt = text.split('\n')
105 wrp = map(lambda x:textwrap.wrap(x,width),splitt)
106 wrpd = map('\n'.join, wrp)
107 return '\n'.join(wrpd)
108
109 #-----------------------------------------------------------------------------
110 98 # Classes and functions
111 99 #-----------------------------------------------------------------------------
112 100 class Exporter(Configurable):
@@ -220,7 +208,7 b' class Exporter(Configurable):'
220 208 self.env.filters['markdown2latex'] = markdown2latex
221 209 self.env.filters['markdown2rst'] = markdown2rst
222 210 self.env.filters['get_lines'] = get_lines
223 self.env.filters['wrap'] = wrap
211 self.env.filters['wrap'] = _wrap
224 212 self.env.filters['rm_dollars'] = _rm_dollars
225 213 self.env.filters['rm_math_space'] = rm_math_space
226 214 self.env.filters['highlight2html'] = highlight
@@ -301,18 +289,22 b' class Exporter(Configurable):'
301 289 return nb, resources
302 290
303 291
292 #TODO: Comment me.
304 293 def _rm_fake(strng):
305 294 return strng.replace('/files/', '')
306 295
307 296
297 #TODO: Comment me.
308 298 def _rm_dollars(strng):
309 299 return strng.strip('$')
310 300
311 301
302 #TODO: Comment me.
312 303 def _python_comment(string):
313 304 return '# '+'\n# '.join(string.split('\n'))
314 305
315 306
307 #TODO: Comment me.
316 308 def _escape_tex(value):
317 309 newval = value
318 310 for pattern, replacement in LATEX_SUBS:
General Comments 0
You need to be logged in to leave comments. Login now