@@ -57,6 +57,7 @@ def __init__(self, document, builder):
5757 self .states = [[]]
5858 self .stateindent = [0 ]
5959 self .list_counter = []
60+ self .list_formatter = []
6061 self .sectionlevel = 0
6162 self .table = None
6263 if self .builder .config .rst_indent :
@@ -477,33 +478,35 @@ def visit_transition(self, node):
477478 raise nodes .SkipNode
478479
479480 def visit_bullet_list (self , node ):
480- self .list_counter .append (- 1 )
481+ def bullet_list_format (counter ):
482+ return '*'
483+ self .list_counter .append (- 1 ) # TODO: just 0 is fine.
484+ self .list_formatter .append (bullet_list_format )
481485 def depart_bullet_list (self , node ):
482486 self .list_counter .pop ()
487+ self .list_formatter .pop ()
483488
484489 def visit_enumerated_list (self , node ):
490+ def enumerated_list_format (counter ):
491+ return str (counter ) + '.'
485492 self .list_counter .append (0 )
493+ self .list_formatter .append (enumerated_list_format )
486494 def depart_enumerated_list (self , node ):
487495 self .list_counter .pop ()
496+ self .list_formatter .pop ()
488497
489498 def visit_list_item (self , node ):
490- if self .list_counter [- 1 ] == - 1 :
491- # bullet list
492- self .new_state (self .indent )
493- elif self .list_counter [- 1 ] == - 2 :
494- # definition list
495- pass
496- else :
497- # enumerated list
498- self .list_counter [- 1 ] += 1
499- self .new_state (len (str (self .list_counter [- 1 ])) + self .indent )
499+ self .list_counter [- 1 ] += 1
500+ bullet_formatter = self .list_formatter [- 1 ]
501+ bullet = bullet_formatter (self .list_counter [- 1 ])
502+ indent = max (self .indent , len (bullet ) + 1 )
503+ self .new_state (indent )
500504 def depart_list_item (self , node ):
501- if self .list_counter [- 1 ] == - 1 :
502- self .end_state (first = '* ' , end = None )
503- elif self .list_counter [- 1 ] == - 2 :
504- pass
505- else :
506- self .end_state (first = '%s. ' % self .list_counter [- 1 ], end = None )
505+ # formatting to make the string `self.stateindent[-1]` chars long.
506+ format = '%%-%ds' % (self .stateindent [- 1 ])
507+ bullet_formatter = self .list_formatter [- 1 ]
508+ bullet = format % bullet_formatter (self .list_counter [- 1 ])
509+ self .end_state (first = bullet , end = None )
507510
508511 def visit_definition_list (self , node ):
509512 pass
0 commit comments