Show More
@@ -553,3 +553,19 b' def decorateblocks(blocks, width):' | |||
|
553 | 553 | text = formatblocks(s[2], width) |
|
554 | 554 | lines.append([(section, l) for l in text.splitlines(True)]) |
|
555 | 555 | return lines |
|
556 | ||
|
557 | def maketable(data, indent=0, header=False): | |
|
558 | '''Generate an RST table for the given table data''' | |
|
559 | ||
|
560 | widths = [max(encoding.colwidth(e) for e in c) for c in zip(*data)] | |
|
561 | indent = ' ' * indent | |
|
562 | f = indent + ' '.join('%%-%ds' % w for w in widths) + '\n' | |
|
563 | div = indent + ' '.join('=' * w for w in widths) + '\n' | |
|
564 | ||
|
565 | out = [div] | |
|
566 | for row in data: | |
|
567 | out.append(f % tuple(row)) | |
|
568 | if header and len(data) > 1: | |
|
569 | out.insert(2, div) | |
|
570 | out.append(div) | |
|
571 | return ''.join(out) |
@@ -232,14 +232,13 b' Empty comment above' | |||
|
232 | 232 | |
|
233 | 233 | debugformat('comments', comments, 30) |
|
234 | 234 | |
|
235 | table = """ | |
|
236 | === === === | |
|
237 | a b c | |
|
238 | === === === | |
|
239 | 1 2 3 | |
|
240 | foo bar baz | |
|
241 | aa bb sdfsdfsdf this line is way too long for this cell. | |
|
242 | === === === | |
|
243 | """ | |
|
235 | ||
|
236 | data = [['a', 'b', 'c'], | |
|
237 | ['1', '2', '3'], | |
|
238 | ['foo', 'bar', 'baz this list is very very very long man']] | |
|
239 | ||
|
240 | table = minirst.maketable(data, 2, True) | |
|
241 | ||
|
242 | print table | |
|
244 | 243 | |
|
245 | 244 | debugformat('table', table, 30) |
@@ -388,15 +388,21 b' Some text.' | |||
|
388 | 388 | Empty comment above |
|
389 | 389 | ---------------------------------------------------------------------- |
|
390 | 390 | |
|
391 | === === ======================================== | |
|
392 | a b c | |
|
393 | === === ======================================== | |
|
394 | 1 2 3 | |
|
395 | foo bar baz this list is very very very long man | |
|
396 | === === ======================================== | |
|
397 | ||
|
391 | 398 | table formatted to fit within 30 characters: |
|
392 | 399 | ---------------------------------------------------------------------- |
|
393 | 400 | a b c |
|
394 | 401 | ------------------------------ |
|
395 | 402 | 1 2 3 |
|
396 | foo bar baz | |
|
397 | aa bb sdfsdfsdf this line | |
|
398 | is way too long for | |
|
399 | this cell. | |
|
403 | foo bar baz this list is | |
|
404 | very very very long | |
|
405 | man | |
|
400 | 406 | |
|
401 | 407 | ---------------------------------------------------------------------- |
|
402 | 408 |
General Comments 0
You need to be logged in to leave comments.
Login now