@@ -433,12 +433,12 @@ def block(self, text):
433433 r'(?::(?P<cite>\S+))? (?P<content>.*)$' .format (tre ,
434434 align_re_s , cls_re_s ))
435435 match = re .search (pattern , line , flags = re .S | re .U )
436+ if out :
437+ last_item_is_a_shelf = out [- 1 ] in self .shelf
436438 # tag specified on this line.
437439 if match :
438440 # if we had a previous extended tag but not this time, close up
439441 # the tag
440- if out :
441- last_item_is_a_shelf = out [- 1 ] in self .shelf
442442 if ext and match .group ('tag' ) and last_item_is_a_shelf :
443443 content = out .pop ()
444444 content = generate_tag (block .inner_tag , content ,
@@ -467,9 +467,14 @@ def block(self, text):
467467 if ext and out :
468468 line = '{0}\n \n {1}' .format (out .pop (), line )
469469 whitespace = ' \t \n \r \f \v '
470- if ext or not line [0 ] in whitespace :
470+ try :
471+ line_first_char_blank = line [0 ] in whitespace
472+ except IndexError :
473+ line_first_char_blank = True
474+ if ext or not line_first_char_blank :
471475 block = Block (self , tag , atts , ext , cite , line )
472- if block .tag == 'p' and not has_raw_text (block .content ):
476+ if (block .tag == 'p' and not has_raw_text (block .content )
477+ or last_item_is_a_shelf ):
473478 line = block .content
474479 else :
475480 line = generate_tag (block .outer_tag , block .content ,
0 commit comments