Show More
@@ -99,8 +99,8 b' def escape(text):' | |||
|
99 | 99 | para_re = None |
|
100 | 100 | space_re = None |
|
101 | 101 | |
|
102 | def fill(text, width): | |
|
103 | '''fill many paragraphs.''' | |
|
102 | def fill(text, width, initindent = '', hangindent = ''): | |
|
103 | '''fill many paragraphs with optional indentation.''' | |
|
104 | 104 | global para_re, space_re |
|
105 | 105 | if para_re is None: |
|
106 | 106 | para_re = re.compile('(\n\n|\n\\s*[-*]\\s*)', re.M) |
@@ -121,7 +121,8 b' def fill(text, width):' | |||
|
121 | 121 | yield text[start:m.start(0)], m.group(1) |
|
122 | 122 | start = m.end(1) |
|
123 | 123 | |
|
124 |
return "".join([space_re.sub(' ', util.wrap(para, width |
|
|
124 | return "".join([util.wrap(space_re.sub(' ', util.wrap(para, width)), | |
|
125 | width, initindent, hangindent) + rest | |
|
125 | 126 | for para, rest in findparas()]) |
|
126 | 127 | |
|
127 | 128 | def fill68(text): |
@@ -299,18 +299,29 b' def rstdoc(context, mapping, args):' | |||
|
299 | 299 | return minirst.format(text, style=style, keep=['verbose']) |
|
300 | 300 | |
|
301 | 301 | def fill(context, mapping, args): |
|
302 |
if not (1 <= len(args) <= |
|
|
303 |
raise error.ParseError(_("fill expects one |
|
|
302 | if not (1 <= len(args) <= 4): | |
|
303 | raise error.ParseError(_("fill expects one to four arguments")) | |
|
304 | 304 | |
|
305 | 305 | text = stringify(args[0][0](context, mapping, args[0][1])) |
|
306 | 306 | width = 76 |
|
307 | if len(args) == 2: | |
|
307 | initindent = '' | |
|
308 | hangindent = '' | |
|
309 | if 2 <= len(args) <= 4: | |
|
308 | 310 | try: |
|
309 | 311 | width = int(stringify(args[1][0](context, mapping, args[1][1]))) |
|
310 | 312 | except ValueError: |
|
311 | 313 | raise error.ParseError(_("fill expects an integer width")) |
|
314 | try: | |
|
315 | initindent = stringify(args[2][0](context, mapping, args[2][1])) | |
|
316 | initindent = stringify(runtemplate(context, mapping, | |
|
317 | compiletemplate(initindent, context))) | |
|
318 | hangindent = stringify(args[3][0](context, mapping, args[3][1])) | |
|
319 | hangindent = stringify(runtemplate(context, mapping, | |
|
320 | compiletemplate(hangindent, context))) | |
|
321 | except IndexError: | |
|
322 | pass | |
|
312 | 323 | |
|
313 | return templatefilters.fill(text, width) | |
|
324 | return templatefilters.fill(text, width, initindent, hangindent) | |
|
314 | 325 | |
|
315 | 326 | def date(context, mapping, args): |
|
316 | 327 | if not (1 <= len(args) <= 2): |
General Comments 0
You need to be logged in to leave comments.
Login now