@@ -227,7 +227,8 @@ def html(self):
227
227
)
228
228
229
229
230
- def cell_output_to_nodes (outputs , data_priority , write_stderr , dir , thebe_config ):
230
+ def cell_output_to_nodes (outputs , data_priority , write_stderr , dir ,
231
+ thebe_config , inline = False ):
231
232
"""Convert a jupyter cell with outputs and filenames to doctree nodes.
232
233
233
234
Parameters
@@ -242,12 +243,22 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
242
243
to the source folder prefixed with ``/``.
243
244
thebe_config: dict
244
245
Thebelab configuration object or None
246
+ inline: False
247
+ Whether the nodes will be placed in-line with the text.
245
248
246
249
Returns
247
250
-------
248
251
to_add : list of docutils nodes
249
252
Each output, converted into a docutils node.
250
253
"""
254
+ # If we're in `inline` mode, ensure that we don't add block-level nodes
255
+ if inline is True :
256
+ literal_node = docutils .nodes .literal
257
+ math_node = docutils .nodes .math
258
+ else :
259
+ literal_node = docutils .nodes .literal_block
260
+ math_node = math_block
261
+
251
262
to_add = []
252
263
for output in outputs :
253
264
output_type = output ["output_type" ]
@@ -265,19 +276,22 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
265
276
# Not setting "rawsource" disables Pygment hightlighting, which
266
277
# would otherwise add a <div class="highlight">.
267
278
268
- container = docutils .nodes .container (classes = ["stderr" ])
269
- container .append (
270
- docutils .nodes .literal_block (
271
- text = output ["text" ],
272
- rawsource = "" , # disables Pygment highlighting
273
- language = "none" ,
274
- classes = ["stderr" ],
275
- )
279
+ literal = literal_node (
280
+ text = output ["text" ],
281
+ rawsource = "" , # disables Pygment highlighting
282
+ language = "none" ,
283
+ classes = ["stderr" ],
276
284
)
277
- to_add .append (container )
285
+ if inline is True :
286
+ # In this case, we don't wrap the text in containers
287
+ to_add .append (literal )
288
+ else :
289
+ container = docutils .nodes .container (classes = ["stderr" ])
290
+ container .append (literal )
291
+ to_add .append (container )
278
292
else :
279
293
to_add .append (
280
- docutils . nodes . literal_block (
294
+ literal_node (
281
295
text = output ["text" ],
282
296
rawsource = output ["text" ],
283
297
language = "none" ,
@@ -288,7 +302,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
288
302
traceback = "\n " .join (output ["traceback" ])
289
303
text = nbconvert .filters .strip_ansi (traceback )
290
304
to_add .append (
291
- docutils . nodes . literal_block (
305
+ literal_node (
292
306
text = text ,
293
307
rawsource = text ,
294
308
language = "ipythontb" ,
@@ -325,7 +339,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
325
339
)
326
340
elif mime_type == "text/latex" :
327
341
to_add .append (
328
- math_block (
342
+ math_node (
329
343
text = strip_latex_delimiters (data ),
330
344
nowrap = False ,
331
345
number = None ,
@@ -334,7 +348,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
334
348
)
335
349
elif mime_type == "text/plain" :
336
350
to_add .append (
337
- docutils . nodes . literal_block (
351
+ literal_node (
338
352
text = data ,
339
353
rawsource = data ,
340
354
language = "none" ,
0 commit comments