comparison mercurial/minirst.py @ 26113:9b70eda7529c

help: distinguish sections when multiple match (issue4802)
author timeless@mozdev.org
date Sun, 30 Aug 2015 19:03:38 -0400
parents 05d97407a8d1
children 65e41f388970
comparison
equal deleted inserted replaced
26112:cb6cfbf21735 26113:9b70eda7529c
654 return text 654 return text
655 655
656 def format(text, width=80, indent=0, keep=None, style='plain', section=None): 656 def format(text, width=80, indent=0, keep=None, style='plain', section=None):
657 """Parse and format the text according to width.""" 657 """Parse and format the text according to width."""
658 blocks, pruned = parse(text, indent, keep or []) 658 blocks, pruned = parse(text, indent, keep or [])
659 parents = []
659 if section: 660 if section:
660 sections = getsections(blocks) 661 sections = getsections(blocks)
661 blocks = [] 662 blocks = []
662 i = 0 663 i = 0
663 while i < len(sections): 664 while i < len(sections):
664 name, nest, b = sections[i] 665 name, nest, b = sections[i]
666 del parents[nest:]
667 parents.append(name)
665 if name == section: 668 if name == section:
669 b[0]['path'] = parents[3:]
666 blocks.extend(b) 670 blocks.extend(b)
667 671
668 ## Also show all subnested sections 672 ## Also show all subnested sections
669 while i + 1 < len(sections) and sections[i + 1][1] > nest: 673 while i + 1 < len(sections) and sections[i + 1][1] > nest:
670 i += 1 674 i += 1
672 i += 1 676 i += 1
673 677
674 if style == 'html': 678 if style == 'html':
675 text = formathtml(blocks) 679 text = formathtml(blocks)
676 else: 680 else:
681 if len([b for b in blocks if b['type'] == 'definition']) > 1:
682 i = 0
683 while i < len(blocks):
684 if blocks[i]['type'] == 'definition':
685 if 'path' in blocks[i]:
686 blocks[i]['lines'][0] = '"%s"' % '.'.join(
687 blocks[i]['path'])
688 i += 1
677 text = ''.join(formatblock(b, width) for b in blocks) 689 text = ''.join(formatblock(b, width) for b in blocks)
678 if keep is None: 690 if keep is None:
679 return text 691 return text
680 else: 692 else:
681 return text, pruned 693 return text, pruned