Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] allow toggling inputs and outputs #436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'sphinxcontrib.bibtex', # for bibliographic references
'sphinxcontrib.rsvgconverter', # for SVG->PDF conversion in LaTeX output
'sphinx_gallery.load_style', # load CSS for gallery (needs SG >= 0.6)
'sphinx_togglebutton',
]

# Default language for syntax highlighting in reST and Markdown cells:
Expand Down
49 changes: 47 additions & 2 deletions doc/hidden-cells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,51 @@
"source": [
"This is the cell after the hidden cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Toggling Cells\n",
"\n",
"You can make a cell toggle-able by adding \"hide_input\" to the cell metadata tags\n",
"\n",
"TODO: check how adding a tag is explained in other parts of doc"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": [
"toggle_input"
]
},
"outputs": [],
"source": [
"1 + 14"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"tags": [
"hide_output"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"my output is hidden\n"
]
}
],
"source": [
"print(\"my output is hidden\")"
]
}
],
"metadata": {
Expand All @@ -97,9 +142,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ sphinxcontrib-svg2pdfconverter
ipywidgets
sphinx-copybutton
sphinx-gallery
sphinx-togglebutton
jupytext
5 changes: 5 additions & 0 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
{%- if not cell.outputs %}
:no-output:
{%- endif %}
{%- if 'toggle_input' in cell.metadata.tags %}
:class: toggle
{%- endif %}

{{ cell.source.strip('\n') | indent }}
{% endblock input %}
Expand Down Expand Up @@ -1045,6 +1048,7 @@ def _create_code_nodes(directive):
outer_classes = ['nbinput']
if 'no-output' in directive.options:
outer_classes.append('nblast')
outer_classes.append(directive.options.get('class', ''))
inner_classes = ['input_area']
prompt_template = config.nbsphinx_input_prompt
if not execution_count:
Expand Down Expand Up @@ -1122,6 +1126,7 @@ class NbInput(rst.Directive):
'empty-lines-before': rst.directives.nonnegative_int,
'empty-lines-after': rst.directives.nonnegative_int,
'no-output': rst.directives.flag,
'class': rst.directives.unchanged,
}
has_content = True

Expand Down