Show More
@@ -268,6 +268,9 b' def findtables(blocks):' | |||||
268 | block['type'] = 'table' |
|
268 | block['type'] = 'table' | |
269 | block['header'] = False |
|
269 | block['header'] = False | |
270 | div = block['lines'][0] |
|
270 | div = block['lines'][0] | |
|
271 | ||||
|
272 | # column markers are ASCII so we can calculate column | |||
|
273 | # position in bytes | |||
271 | columns = [x for x in xrange(len(div)) |
|
274 | columns = [x for x in xrange(len(div)) | |
272 | if div[x] == '=' and (x == 0 or div[x - 1] == ' ')] |
|
275 | if div[x] == '=' and (x == 0 or div[x - 1] == ' ')] | |
273 | rows = [] |
|
276 | rows = [] | |
@@ -276,12 +279,19 b' def findtables(blocks):' | |||||
276 | block['header'] = True |
|
279 | block['header'] = True | |
277 | continue |
|
280 | continue | |
278 | row = [] |
|
281 | row = [] | |
|
282 | # we measure columns not in bytes or characters but in | |||
|
283 | # colwidth which makes things tricky | |||
|
284 | pos = columns[0] # leading whitespace is bytes | |||
279 | for n, start in enumerate(columns): |
|
285 | for n, start in enumerate(columns): | |
280 | if n + 1 < len(columns): |
|
286 | if n + 1 < len(columns): | |
281 |
|
|
287 | width = columns[n + 1] - start | |
|
288 | v = encoding.getcols(l, pos, width) # gather columns | |||
|
289 | pos += len(v) # calculate byte position of end | |||
|
290 | row.append(v.strip()) | |||
282 | else: |
|
291 | else: | |
283 |
row.append(l[s |
|
292 | row.append(l[pos:].strip()) | |
284 | rows.append(row) |
|
293 | rows.append(row) | |
|
294 | ||||
285 | block['table'] = rows |
|
295 | block['table'] = rows | |
286 |
|
296 | |||
287 | return blocks |
|
297 | return blocks | |
@@ -436,7 +446,11 b' def formatblock(block, width):' | |||||
436 | f = ' '.join('%%-%ds' % n for n in widths) |
|
446 | f = ' '.join('%%-%ds' % n for n in widths) | |
437 |
|
447 | |||
438 | for row in table: |
|
448 | for row in table: | |
439 |
l = |
|
449 | l = [] | |
|
450 | for w, v in zip(widths, row): | |||
|
451 | pad = ' ' * (w - encoding.colwidth(v)) | |||
|
452 | l.append(v + pad) | |||
|
453 | l = ' '.join(l) | |||
440 | l = util.wrap(l, width=width, initindent=indent, hangindent=hang) |
|
454 | l = util.wrap(l, width=width, initindent=indent, hangindent=hang) | |
441 | if not text and block['header']: |
|
455 | if not text and block['header']: | |
442 | text = l + '\n' + indent + '-' * (min(width, span)) + '\n' |
|
456 | text = l + '\n' + indent + '-' * (min(width, span)) + '\n' | |
@@ -551,12 +565,15 b' def maketable(data, indent=0, header=Fal' | |||||
551 |
|
565 | |||
552 | widths = [max(encoding.colwidth(e) for e in c) for c in zip(*data)] |
|
566 | widths = [max(encoding.colwidth(e) for e in c) for c in zip(*data)] | |
553 | indent = ' ' * indent |
|
567 | indent = ' ' * indent | |
554 | f = indent + ' '.join('%%-%ds' % w for w in widths) + '\n' |
|
|||
555 | div = indent + ' '.join('=' * w for w in widths) + '\n' |
|
568 | div = indent + ' '.join('=' * w for w in widths) + '\n' | |
556 |
|
569 | |||
557 | out = [div] |
|
570 | out = [div] | |
558 | for row in data: |
|
571 | for row in data: | |
559 | out.append(f % tuple(row)) |
|
572 | l = [] | |
|
573 | for w, v in zip(widths, row): | |||
|
574 | pad = ' ' * (w - encoding.colwidth(v)) | |||
|
575 | l.append(v + pad) | |||
|
576 | out.append(indent + ' '.join(l) + "\n") | |||
560 | if header and len(data) > 1: |
|
577 | if header and len(data) > 1: | |
561 | out.insert(2, div) |
|
578 | out.insert(2, div) | |
562 | out.append(div) |
|
579 | out.append(div) |
General Comments 0
You need to be logged in to leave comments.
Login now