@@ -229,7 +229,8 @@ def html(self):
229229 )
230230
231231
232- def cell_output_to_nodes (outputs , data_priority , write_stderr , out_dir , thebe_config ):
232+ def cell_output_to_nodes (outputs , data_priority , write_stderr , out_dir ,
233+ thebe_config , inline = False ):
233234 """Convert a jupyter cell with outputs and filenames to doctree nodes.
234235
235236 Parameters
@@ -244,12 +245,22 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, out_dir, thebe_co
244245 to the source folder prefixed with ``/``.
245246 thebe_config: dict
246247 Thebelab configuration object or None
248+ inline: False
249+ Whether the nodes will be placed in-line with the text.
247250
248251 Returns
249252 -------
250253 to_add : list of docutils nodes
251254 Each output, converted into a docutils node.
252255 """
256+ # If we're in `inline` mode, ensure that we don't add block-level nodes
257+ if inline :
258+ literal_node = docutils .nodes .literal
259+ math_node = docutils .nodes .math
260+ else :
261+ literal_node = docutils .nodes .literal_block
262+ math_node = math_block
263+
253264 to_add = []
254265 for output in outputs :
255266 output_type = output ["output_type" ]
@@ -267,19 +278,22 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, out_dir, thebe_co
267278 # Not setting "rawsource" disables Pygment hightlighting, which
268279 # would otherwise add a <div class="highlight">.
269280
270- container = docutils .nodes .container (classes = ["stderr" ])
271- container .append (
272- docutils .nodes .literal_block (
273- text = output ["text" ],
274- rawsource = "" , # disables Pygment highlighting
275- language = "none" ,
276- classes = ["stderr" ],
277- )
281+ literal = literal_node (
282+ text = output ["text" ],
283+ rawsource = "" , # disables Pygment highlighting
284+ language = "none" ,
285+ classes = ["stderr" ],
278286 )
279- to_add .append (container )
287+ if inline :
288+ # In this case, we don't wrap the text in containers
289+ to_add .append (literal )
290+ else :
291+ container = docutils .nodes .container (classes = ["stderr" ])
292+ container .append (literal )
293+ to_add .append (container )
280294 else :
281295 to_add .append (
282- docutils . nodes . literal_block (
296+ literal_node (
283297 text = output ["text" ],
284298 rawsource = output ["text" ],
285299 language = "none" ,
@@ -290,7 +304,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, out_dir, thebe_co
290304 traceback = "\n " .join (output ["traceback" ])
291305 text = nbconvert .filters .strip_ansi (traceback )
292306 to_add .append (
293- docutils . nodes . literal_block (
307+ literal_node (
294308 text = text ,
295309 rawsource = text ,
296310 language = "ipythontb" ,
@@ -325,7 +339,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, out_dir, thebe_co
325339 )
326340 elif mime_type == "text/latex" :
327341 to_add .append (
328- math_block (
342+ math_node (
329343 text = strip_latex_delimiters (data ),
330344 nowrap = False ,
331345 number = None ,
@@ -334,7 +348,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, out_dir, thebe_co
334348 )
335349 elif mime_type == "text/plain" :
336350 to_add .append (
337- docutils . nodes . literal_block (
351+ literal_node (
338352 text = data ,
339353 rawsource = data ,
340354 language = "none" ,
0 commit comments