mercurial/minirst.py
changeset 15039 c981f4a9ea74
parent 15038 3f4d337cb80a
child 15102 a7e375d087f6
equal deleted inserted replaced
15038:3f4d337cb80a 15039:c981f4a9ea74
   551     for s in getsections(blocks):
   551     for s in getsections(blocks):
   552         section = s[0]
   552         section = s[0]
   553         text = formatblocks(s[2], width)
   553         text = formatblocks(s[2], width)
   554         lines.append([(section, l) for l in text.splitlines(True)])
   554         lines.append([(section, l) for l in text.splitlines(True)])
   555     return lines
   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)