@@ -187,6 +187,21 @@ def run(self):
187
187
self .assert_has_content ()
188
188
content = self .content
189
189
190
+ emphasize_linespec = self .options .get ('emphasize-lines' )
191
+ if emphasize_linespec :
192
+ try :
193
+ nlines = len (content )
194
+ hl_lines = parselinenos (emphasize_linespec , nlines )
195
+ if any (i >= nlines for i in hl_lines ):
196
+ logger .warning (
197
+ 'Line number spec is out of range(1-{}): {}' .format (
198
+ nlines , emphasize_linespec ), location = location )
199
+ hl_lines = [i + 1 for i in hl_lines if i < nlines ]
200
+ except ValueError as err :
201
+ return [self .state .document .reporter .warning (err , line = self .lineno )]
202
+ else :
203
+ hl_lines = []
204
+
190
205
return [JupyterCellNode (
191
206
'' ,
192
207
docutils .nodes .literal_block (
@@ -196,10 +211,9 @@ def run(self):
196
211
hide_output = ('hide-output' in self .options ),
197
212
code_below = ('code-below' in self .options ),
198
213
linenos = ('linenos' in self .options ),
199
- emphasize_lines = self . options . get ( 'emphasize-lines' ) ,
214
+ emphasize_lines = hl_lines ,
200
215
raises = self .options .get ('raises' ),
201
216
stderr = ('stderr' in self .options ),
202
- _location = location ,
203
217
)]
204
218
205
219
@@ -420,14 +434,8 @@ def apply(self):
420
434
source ['highlight_args' ] = {'linenostart' : linenostart }
421
435
linenostart += nlines
422
436
423
- emphasize_linespec = node ['emphasize_lines' ]
424
- if emphasize_linespec :
425
- hl_lines = parselinenos (emphasize_linespec , nlines )
426
- if any (i >= nlines for i in hl_lines ):
427
- logger .warning (
428
- 'Line number spec is out of range(1-{}): {}' .format (
429
- nlines , emphasize_linespec ), location = node ['_location' ])
430
- hl_lines = [i + 1 for i in hl_lines if i < nlines ]
437
+ hl_lines = node ['emphasize_lines' ]
438
+ if hl_lines :
431
439
highlight_args = source .setdefault ('highlight_args' , {})
432
440
highlight_args ['hl_lines' ] = hl_lines
433
441
0 commit comments