@@ -73,27 +73,31 @@ def test_notebook_header(notebook):
7373 in_header = False
7474 elif item ['cell_type' ] == 'markdown' :
7575 if in_header :
76+ in_code_cell = False
7677 for line in item ['source' ]:
7778 line = line .strip ()
78- if not has_number and line .startswith ('#' ):
79- current_level = line .split ()[0 ]
80- assert current_level == '#' ,\
81- (f"\n { notebook } \n header line { line } :\n "
82- f"{ error_instructions } " )
83- header_level = current_level
84- header_number = line .split ()[1 ].strip ()
85- assert header_number [:2 ].isdigit (),\
86- (f"\n { notebook } \n header line { line } :\n "
79+ if line .startswith ('```' ):
80+ in_code_cell = not in_code_cell
81+ if not in_code_cell :
82+ if not has_number and line .startswith ('#' ):
83+ current_level = line .split ()[0 ]
84+ assert current_level == '#' ,\
85+ (f"\n { notebook } \n header line { line } :\n "
8786 f"{ error_instructions } " )
88- assert header_number [- 1 ] == ':' ,\
89- (f"\n { notebook } \n header line { line } :\n "
87+ header_level = current_level
88+ header_number = line .split ()[1 ].strip ()
89+ assert header_number [:2 ].isdigit (),\
90+ (f"\n { notebook } \n header line { line } :\n "
91+ f"{ error_instructions } " )
92+ assert header_number [- 1 ] == ':' ,\
93+ (f"\n { notebook } \n header line { line } :\n "
94+ f"{ error_instructions } " )
95+ has_number = True
96+ elif line .strip ().startswith ('#' ):
97+ current_level = line .split ()[0 ]
98+ assert len (current_level ) > 1 ,\
99+ (f"\n { notebook } \n line { line } :\n "
90100 f"{ error_instructions } " )
91- has_number = True
92- elif line .strip ().startswith ('#' ):
93- current_level = line .split ()[0 ]
94- assert len (current_level ) > 1 ,\
95- (f"\n { notebook } \n line { line } :\n "
96- f"{ error_instructions } " )
97101 else :
98102 in_code_cell = False
99103 for line in item ['source' ]:
@@ -105,4 +109,4 @@ def test_notebook_header(notebook):
105109 assert len (current_level ) > 1 ,\
106110 (f"\n { notebook } \n line { line } :\n "
107111 f"{ error_instructions } " )
108-
112+
0 commit comments