Mercurial > hg-stable
diff mercurial/minirst.py @ 22587:c3c3dd31fe1c
help: basic support for showing only specified topic sections
For instance, 'hg help config.files' will show only the Files section.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 30 Sep 2014 16:40:10 -0500 |
parents | 19bd8bda6bb2 |
children | 3f808549d426 |
line wrap: on
line diff
--- a/mercurial/minirst.py Tue Sep 30 15:55:30 2014 -0500 +++ b/mercurial/minirst.py Tue Sep 30 16:40:10 2014 -0500 @@ -648,9 +648,15 @@ text = ''.join(formatblock(b, width) for b in blocks) return text -def format(text, width=80, indent=0, keep=None, style='plain'): +def format(text, width=80, indent=0, keep=None, style='plain', section=None): """Parse and format the text according to width.""" blocks, pruned = parse(text, indent, keep or []) + if section: + sections = getsections(blocks) + blocks = [] + for name, nest, b in sections: + if name == section: + blocks = b if style == 'html': text = formathtml(blocks) else: @@ -665,6 +671,14 @@ nest = "" level = 0 secs = [] + + def getname(b): + x = b['lines'][0] + x = x.lower().strip('"') + if '(' in x: + x = x.split('(')[0] + return x + for b in blocks: if b['type'] == 'section': i = b['underline'] @@ -672,7 +686,14 @@ nest += i level = nest.index(i) + 1 nest = nest[:level] - secs.append((b['lines'][0], level, [b])) + secs.append((getname(b), level, [b])) + if b['type'] == 'definition': + i = ' ' + if i not in nest: + nest += i + level = nest.index(i) + 1 + nest = nest[:level] + secs.append((getname(b), level, [b])) else: if not secs: # add an initial empty section