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