diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3950,13 +3950,16 @@ def remove(ui, repo, *pats, **opts): file states (columns) and option combinations (rows). The file states are Added [A], Clean [C], Modified [M] and Missing [!] (as reported by :hg:`status`). The actions are Warn, Remove (from - branch) and Delete (from disk):: - - A C M ! - none W RD W R - -f R RD RD R - -A W W W R - -Af R R R R + branch) and Delete (from disk): + + ======= == == == == + A C M ! + ======= == == == == + none W RD W R + -f R RD RD R + -A W W W R + -Af R R R R + ======= == == == == Note that remove never deletes files in Added [A] state from the working directory, not even if option --force is specified. diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -103,6 +103,7 @@ def findliteralblocks(blocks): r'((.*) +)(.*)$') _fieldre = re.compile(r':(?![: ])([^:]*)(? 4 and + _tablere.match(block['lines'][0]) and + block['lines'][0] == block['lines'][-1]): + block['type'] = 'table' + block['header'] = False + div = block['lines'][0] + columns = [x for x in xrange(len(div)) + if div[x] == '=' and (x == 0 or div[x - 1] == ' ')] + rows = [] + for l in block['lines'][1:-1]: + if l == div: + block['header'] = True + continue + row = [] + for n, start in enumerate(columns): + if n + 1 < len(columns): + row.append(l[start:columns[n + 1]].strip()) + else: + row.append(l[start:].strip()) + rows.append(row) + block['table'] = rows + + return blocks + def findsections(blocks): """Finds sections. @@ -392,6 +433,24 @@ def formatblock(block, width): if block['type'] == 'section': underline = encoding.colwidth(block['lines'][0]) * block['underline'] return "%s%s\n%s%s" % (indent, block['lines'][0],indent, underline) + if block['type'] == 'table': + table = block['table'] + # compute column widths + widths = [max([encoding.colwidth(e) for e in c]) for c in zip(*table)] + text = '' + span = sum(widths) + len(widths) - 1 + indent = ' ' * block['indent'] + hang = ' ' * (len(indent) + span - widths[-1]) + f = ' '.join('%%-%ds' % n for n in widths) + + for row in table: + l = f % tuple(row) + l = util.wrap(l, width=width, initindent=indent, hangindent=hang) + if not text and block['header']: + text = l + '\n' + indent + '-' * (min(width, span)) + '\n' + else: + text += l + "\n" + return text if block['type'] == 'definition': term = indent + block['lines'][0] hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) @@ -440,6 +499,7 @@ def parse(text, indent=0, keep=None): for b in blocks: b['indent'] += indent blocks = findliteralblocks(blocks) + blocks = findtables(blocks) blocks, pruned = prunecontainers(blocks, keep or []) blocks = findsections(blocks) blocks = inlineliterals(blocks) diff --git a/tests/test-minirst.py b/tests/test-minirst.py --- a/tests/test-minirst.py +++ b/tests/test-minirst.py @@ -231,3 +231,15 @@ Empty comment above """ debugformat('comments', comments, 30) + +table = """ + === === === + a b c + === === === + 1 2 3 + foo bar baz + aa bb sdfsdfsdf this line is way too long for this cell. + === === === +""" + +debugformat('table', table, 30) diff --git a/tests/test-minirst.py.out b/tests/test-minirst.py.out --- a/tests/test-minirst.py.out +++ b/tests/test-minirst.py.out @@ -388,3 +388,15 @@ Some text. Empty comment above ---------------------------------------------------------------------- +table formatted to fit within 30 characters: +---------------------------------------------------------------------- + a b c + ------------------------------ + 1 2 3 + foo bar baz + aa bb sdfsdfsdf this line + is way too long for + this cell. + +---------------------------------------------------------------------- +