Skip to content

Commit 330f95b

Browse files
committed
css-related code updates and doc additions
1 parent c27b586 commit 330f95b

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

doc/source/index.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,30 @@ the code. If a document contains ``jupyter-kernel`` directives with ``:id:`` spe
285285
the name provided to ``:id:`` can be used to get the code for the cells belonging to the
286286
that Jupyter session.
287287

288+
Styling options
289+
---------------
290+
291+
The CSS (Cascading Style Sheet) class structure of jupyter-sphinx is the
292+
following::
293+
294+
- jupyter_container
295+
- code_cell
296+
- stderr
297+
- output
298+
299+
If a code cell is not displayed, the output is provided without the
300+
``jupyter_container``. If you want to adjust the styles, add a new stylesheet,
301+
e.g. ``custom.css``, and adjust your ``conf.py`` to load it. How you do so depends on
302+
the theme you are using.
303+
304+
Here is a sample ``custom.css`` file overriding the ``stderr`` background color:
305+
306+
.. code-block:: css
307+
308+
.jupyter_container .stderr {
309+
background-color: #7FFF00;
310+
}
311+
288312
289313
Configuration options
290314
---------------------

jupyter_sphinx/execute.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class JupyterCell(Directive):
134134
If provided, the cell output will not be displayed in the output.
135135
code-below : bool
136136
If provided, the code will be shown below the cell output.
137+
linenos : bool
138+
If provided, the code will be shown with line numbers.
137139
raises : comma separated list of exception types
138140
If provided, a comma-separated list of exception type names that
139141
the cell may raise. If one of the listed execption types is raised
@@ -596,6 +598,8 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
596598

597599

598600
def attach_outputs(output_nodes, node, thebe_config, cm_language):
601+
if not node.attributes["hide_code"]: # only add css if code is displayed
602+
node.attributes["classes"] = ["jupyter_container"]
599603
if thebe_config:
600604
source = node.children[0]
601605
thebe_source = ThebeSourceNode(hide_code=node.attributes['hide_code'],
@@ -604,7 +608,6 @@ def attach_outputs(output_nodes, node, thebe_config, cm_language):
604608
thebe_source.children = [source]
605609

606610
node.children = [thebe_source]
607-
node.attributes["classes"] = ["jupyter_container"] # add jupyter classes even if thebe_config <-- CHECK
608611

609612
if not node.attributes['hide_output']:
610613
thebe_output = ThebeOutputNode()
@@ -614,12 +617,8 @@ def attach_outputs(output_nodes, node, thebe_config, cm_language):
614617
else:
615618
node.children = node.children + [thebe_output]
616619
else:
617-
# Only add container class if code is shown
618620
if node.attributes['hide_code']:
619621
node.children = []
620-
else:
621-
node.attributes["classes"] = ["jupyter_container"]
622-
623622
if not node.attributes['hide_output']:
624623
if node.attributes['code_below']:
625624
node.children = output_nodes + node.children

0 commit comments

Comments
 (0)