##// END OF EJS Templates
minirst: add getsections helper
Matt Mackall -
r15014:a814e986 default
parent child Browse files
Show More
@@ -465,6 +465,25 b' def format(text, width, indent=0, keep=N'
465 else:
465 else:
466 return text, pruned
466 return text, pruned
467
467
468 def getsections(blocks):
469 '''return a list of (section name, nesting level, blocks) tuples'''
470 nest = ""
471 level = 0
472 secs = []
473 for b in blocks:
474 if b['type'] == 'section':
475 i = b['underline']
476 if i not in nest:
477 nest += i
478 level = nest.index(i) + 1
479 nest = nest[:level]
480 secs.append((b['lines'][0], level, [b]))
481 else:
482 if not secs:
483 # add an initial empty section
484 secs = [('', 0, [])]
485 secs[-1][2].append(b)
486 return secs
468
487
469 if __name__ == "__main__":
488 if __name__ == "__main__":
470 from pprint import pprint
489 from pprint import pprint
General Comments 0
You need to be logged in to leave comments. Login now