@@ -494,13 +494,48 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
494
494
if (
495
495
output_type == 'stream'
496
496
):
497
- if not write_stderr and output ["name" ] == "stderr" :
498
- continue
499
- to_add .append (docutils .nodes .literal_block (
500
- text = output ['text' ],
501
- rawsource = output ['text' ],
502
- language = 'none' ,
503
- ))
497
+ if output ["name" ] == "stderr" :
498
+ if not write_stderr :
499
+ continue
500
+ else :
501
+ # Produce a container with an unhighlighted literal block for
502
+ # `stderr` messages.
503
+ #
504
+ # Adds a "stderr" class that can be customized by the user for both
505
+ # the container and the literal_block.
506
+ #
507
+ # Also adds "error" as a base class, which is fairly common
508
+ # class in Sphinx themes. It should result in differenciation
509
+ # from stdout in most standard themes.
510
+ #
511
+ # Not setting "rawsource" disables Pygment hightlighting, which
512
+ # would otherwise add a <div class="highlight"> to the container
513
+ # that would hold the literal_block (<pre>).
514
+
515
+ container = docutils .nodes .container (classes = ["error" , "stderr" ])
516
+ container .append (docutils .nodes .literal_block (
517
+ text = output ['text' ],
518
+ rawsource = '' , # disables Pygment highlighting
519
+ language = 'none' ,
520
+ classes = ["error" , "stderr" ]
521
+ ))
522
+ to_add .append (container )
523
+
524
+ # Alternative, without container
525
+
526
+ # to_add.append(docutils.nodes.literal_block(
527
+ # text=output['text'],
528
+ # rawsource='', # disables Pygment highlighting
529
+ # language='none',
530
+ # classes=["error", "stderr"]
531
+ # ))
532
+
533
+ else :
534
+ to_add .append (docutils .nodes .literal_block (
535
+ text = output ['text' ],
536
+ rawsource = output ['text' ],
537
+ language = 'none' ,
538
+ ))
504
539
elif (
505
540
output_type == 'error'
506
541
):
0 commit comments