##// END OF EJS Templates
minirst: extract function that filters parsed blocks by section name...
Yuya Nishihara -
r39341:200ad3e8 default
parent child Browse files
Show More
@@ -666,8 +666,21 b' def formatblocks(blocks, width):'
666 def format(text, width=80, indent=0, keep=None, style='plain', section=None):
666 def format(text, width=80, indent=0, keep=None, style='plain', section=None):
667 """Parse and format the text according to width."""
667 """Parse and format the text according to width."""
668 blocks, pruned = parse(text, indent, keep or [])
668 blocks, pruned = parse(text, indent, keep or [])
669 if section:
670 blocks = filtersections(blocks, section)
671 if style == 'html':
672 text = formathtml(blocks)
673 else:
674 text = ''.join(formatblock(b, width) for b in blocks)
675 if keep is None:
676 return text
677 else:
678 return text, pruned
679
680 def filtersections(blocks, section):
681 """Select parsed blocks under the specified section"""
669 parents = []
682 parents = []
670 if section:
683 if True:
671 sections = getsections(blocks)
684 sections = getsections(blocks)
672 blocks = []
685 blocks = []
673 i = 0
686 i = 0
@@ -714,14 +727,7 b' def format(text, width=80, indent=0, kee'
714 '.'.join(path + [realline[0]]).replace('"', ''))
727 '.'.join(path + [realline[0]]).replace('"', ''))
715 del blocks[s[0]:real]
728 del blocks[s[0]:real]
716
729
717 if style == 'html':
730 return blocks
718 text = formathtml(blocks)
719 else:
720 text = ''.join(formatblock(b, width) for b in blocks)
721 if keep is None:
722 return text
723 else:
724 return text, pruned
725
731
726 def getsections(blocks):
732 def getsections(blocks):
727 '''return a list of (section name, nesting level, blocks) tuples'''
733 '''return a list of (section name, nesting level, blocks) tuples'''
General Comments 0
You need to be logged in to leave comments. Login now